Community Tip - Did you get called away in the middle of writing a post? Don't worry you can find your unfinished post later in the Drafts section of your profile page. X
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.
Solved! Go to Solution.
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); }
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); }
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
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!