cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Want the oppurtunity to discuss enhancements to PTC products? Join a working group! X

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

asekar
13-Aquamarine

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

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

1 ACCEPTED SOLUTION

Accepted Solutions
A_Macierzynski
14-Alexandrite
(To:asekar)

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

View solution in original post

4 REPLIES 4
supandey
19-Tanzanite
(To:asekar)

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

asekar
13-Aquamarine
(To:supandey)


@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

supandey
19-Tanzanite
(To:asekar)

@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)

A_Macierzynski
14-Alexandrite
(To:asekar)

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

Top Tags