Skip to main content
5-Regular Member
June 25, 2018
Solved

What is the best way to set logged = true against all thing properties through a service

  • June 25, 2018
  • 2 replies
  • 2004 views

What is the best way to set logged = true against all thing properties through a service

Best answer by A_Macierzynski

Hi!

 

You can use my script:

 

var params = {
	category: undefined /* STRING */,
	type: undefined /* BASETYPENAME */,
	dataShape: undefined /* DATASHAPENAME */
};
// result: INFOTABLE dataShape: "PropertyDefinition"
var properties = me.GetPropertyDefinitions(params);

for(var i=0; i<properties.getRowCount(); i++){
	if(!isDefault(properties[i]['name'])){
 	var params = {
 propertyName: properties[i]['name'] /* STRING */,
 enabled: true /* BOOLEAN */
 };
 me.SetPropertyLogging(params);
 }
}

function isDefault(needle)
{
 var defaults = ['name', 'tags', 'thingTemplate', 'description'];
 return (defaults.indexOf(needle) > -1);
} 

It is checking also if property is deafult or not, so it should be exactly what you are looking for.

 

Best Regards,

Adam

2 replies

5-Regular Member
June 25, 2018

Hi @asekar are you looking to use something other than GetPropertyLogging service? Could you elaborate a bit more on the actual use case?

asekar5-Regular MemberAuthor
5-Regular Member
June 25, 2018

@supandey wrote:

Hi @asekar are you looking to use something other than GetPropertyLogging service? Could you elaborate a bit more on the actual use case?


I have many properties already created against a thing. I want to make all these properties "logged". I see that I can use a service SetPropertyLogged. But I will have to pass in each property separately. If there is a way to automatically set logged = true for all the properties, it would make my job easier

5-Regular Member
June 26, 2018

@asekar I don't think there is any out of the box setting that you can enable to make all thing's properties to log. You likely will have to create a custom service which will check this for all the things whose property you want to log and then enable them.

 

May be for all the future creation of Thing and their properties you could include this check in the service (i.e. if you are creating things programatically)

15-Moonstone
June 26, 2018

Hi!

 

You can use my script:

 

var params = {
	category: undefined /* STRING */,
	type: undefined /* BASETYPENAME */,
	dataShape: undefined /* DATASHAPENAME */
};
// result: INFOTABLE dataShape: "PropertyDefinition"
var properties = me.GetPropertyDefinitions(params);

for(var i=0; i<properties.getRowCount(); i++){
	if(!isDefault(properties[i]['name'])){
 	var params = {
 propertyName: properties[i]['name'] /* STRING */,
 enabled: true /* BOOLEAN */
 };
 me.SetPropertyLogging(params);
 }
}

function isDefault(needle)
{
 var defaults = ['name', 'tags', 'thingTemplate', 'description'];
 return (defaults.indexOf(needle) > -1);
} 

It is checking also if property is deafult or not, so it should be exactly what you are looking for.

 

Best Regards,

Adam