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

Community Tip - Did you get an answer that solved your problem? Please mark it as an Accepted Solution so others with the same problem can find the answer easily. X

How to set all properties to "isLogged: true"

binaryPUNCH
12-Amethyst

How to set all properties to "isLogged: true"

Hello. I'm evaluating ThingWorx and trying to import a bunch of Kepserver PLC devices into ThingWorx. Hundreds of tags via. OPC UA and the default must be to log the parameters. There doesn't seem to be an obvious way on how to ensure all added parameters are logged. What's the best way in doing so, could I do a simple API call, perhaps set a default setting on a ThingTemplate, or programatically go through the properties setting the value?

 

I tried the following script but it won't work for me. 

 Error executing service SetAllPropertiesLogged. Message :: Property [IndustrialThing] does not exist 

Anything I logger.debug() doesn't go to the ScriptLog making my developer experience very frustrating.

ACCEPTED SOLUTION

Accepted Solutions

Oh, I managed to fix this by updating the "isDefault" function to include ALL inherited properties. Then the error stopped showing. Ugly hack which must be maintained for any and all inherited properties. Wonder if there is a fix, but at least this works for now.

 

edit: I made it even uglier, but easier to maintain with a try-catch, avoiding the isDefault function.

 

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 */,
            isLogged: true
        };
        me.SetPropertyLogging(params);
    }
}

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

 

View solution in original post

3 REPLIES 3

Oh, I managed to fix this by updating the "isDefault" function to include ALL inherited properties. Then the error stopped showing. Ugly hack which must be maintained for any and all inherited properties. Wonder if there is a fix, but at least this works for now.

 

edit: I made it even uglier, but easier to maintain with a try-catch, avoiding the isDefault function.

 

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 */,
            isLogged: true
        };
        me.SetPropertyLogging(params);
    }
}

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

 

visla
14-Alexandrite
(To:binaryPUNCH)

Hello binaryPUNCH,

 

I have just tested the provided script and it is working for me.

According to the error you have provided, it seems your script is trying to do something with property "IndustrialThing" and that property doesn't exist.

 

- Could you please provide the exact script you are using with the logger.debug() lines that you are trying to use for troubleshooting?

- Where are you exactly running this "SetAllPropertiesLogged" Service? At the ThingTemplate? At the Thing level?

 

Please don't hesitate to contact me if you have any question.

 

Thanks!

Vanessa

binaryPUNCH
12-Amethyst
(To:visla)

Thank you Vanessa, you are right the script does work. My issue was my thing was inheriting from a custom template with more uneditable/read-only properties. So I had to include them in the isDefault function. I ended up simply doing a try-catch to avoid the need entirely, and all is good now! Thanks for the quick response, otherwise!

Announcements


Top Tags