Community Tip - Your Friends List is a way to easily have access to the community members that you interact with the most! X
Hi everybody,
I am not able to set the Cache Method of a Remote Thing Template created via services.
I am using the AddPropertyDefinition function. Since there is no option to set cacheTime directly, I included it in the remoteBindingAspects option, but I am not sure the syntax is correct or whether I can even do that or not:
var remoteAspects={ cacheTime:-1, }; var params = { // defaultValue: undefined /* STRING */, remoteBindingAspects: remoteAspects /* JSON */, // description: undefined /* STRING */, // readOnly: undefined /* BOOLEAN */, type: me.PressProps.rows[i].DataType /* BASETYPENAME */, remote: true /* BOOLEAN */, // remotePropertyName: undefined /* STRING */, // timeout: undefined /* INTEGER */, // pushType: undefined /* STRING */, // dataChangeThreshold: undefined /* NUMBER */, // logged: undefined /* BOOLEAN */, name: me.PressProps.rows[i].PropertyName /* STRING */, // pushThreshold: undefined /* NUMBER */, dataChangeType: "ALWAYS" /* STRING */, // category: undefined /* STRING */, // persistent: undefined /* BOOLEAN */, // dataShape: undefined /* DATASHAPENAME */ }; result= params; ThingTemplates["Press_T"].AddPropertyDefinition(params); }
I have also tried to set the cacheTime in the binding service I am using:
var n=me.PressProps.length; //Bind each property name with its source for (var i=0; i<n; i++) { var CompleteSource = me.PressProps.rows[i].PropertySource_pt1 +'['+PressID+']'+ me.PressProps.rows[i].PropertySource_pt2; var aspects = { industrialDataType: undefined, tagAddress: CompleteSource, scanRate: 1000, tagType: "Static", }; Things[PressName].SetRemotePropertyBinding({ propertyName: me.PressProps.rows[i].PropertyName, sourcePropertyName: undefined, aspects: aspects, // cacheTime: -1, //need to enable this from template }); }
This service is working fine when I apply it to Things that are not created through my template, but (this is my explaination) it does not let me override the default value given by my previously created template (cacheTime=0).
Any idea on how I could solve this issue?
What you are doing should work. If you do this on the Thing Level are you remembering to Restart the Thing?
If I include the "cacheTime=-1" part at Things level I get the following error returned:
"ErrorCode(39beccb4-58cd-4e74-9ece-726f6956263c), Cause(null), Reason(Access was attempted on a null reference variable.), Possible Resolutions(Remove the reference to the null variable within your extension code.)"
which I guess it's the same reason why I cannot manually changed certain properties at things level if they are pre-specified in the thing template.
Seems to imply that this particular field is not being set in the right object.
is this perhaps inside an Aspects object vs. directly in the binding definition?
That script works fine as long as the Thing (whose properties I am trying to bind to remote) does not come from a Thing Template. I therefore believe I need to fix this at Template level.
When defining the properties in the template, maybe there is something I can do with the remoteBindingAspects:
m=me.PressProps.length; for (i=0;i<m;i++){ var remoteAspects={ cacheTime:-1, }; var params = { // defaultValue: undefined /* STRING */, remoteBindingAspects: remoteAspects /* JSON */, // description: undefined /* STRING */, // readOnly: undefined /* BOOLEAN */, type: me.PressProps.rows[i].DataType /* BASETYPENAME */, remote: true /* BOOLEAN */, // remotePropertyName: undefined /* STRING */, // timeout: undefined /* INTEGER */, // pushType: undefined /* STRING */, // dataChangeThreshold: undefined /* NUMBER */, // logged: undefined /* BOOLEAN */, name: me.PressProps.rows[i].PropertyName /* STRING */, // pushThreshold: undefined /* NUMBER */, dataChangeType: "ALWAYS" /* STRING */, // category: undefined /* STRING */, // persistent: undefined /* BOOLEAN */, // dataShape: undefined /* DATASHAPENAME */ }; result= params; ThingTemplates["Press_T"].AddPropertyDefinition(params); }
When I run that script, all properties are correctly added to the template, but the cacheTime option is ignored. Maybe I should specify it somehow in a different way?
According to this article, there is a bug (in ThingWorx Platform 7.2 to 8.5) which causes the following:
Cache options and When Disconnected settings cannot be set programmatically using SetRemotePropertyBinding.
Maybe this bug is the reason why you cannot find a way to set the cacheTime programmatically.
By the way, I found PTC's help files on Programmatically Adding Properties to Things misleading because they claim that you can programmatically set both cacheMethod and cacheInterval, but they do not list the exact valid string parameters for defining the cacheMethod aspect (possibly because there are no valid parameters, hence the above bug report JIRA TW-7615).
In addition to this confusion, there is some more confusion because of the naming of cacheInterval and cacheTime.
Do we have to set the cacheTime in order to specify the cacheMethod? That's what I would deduce from reading exported XML with different properties. But I am not sure about it. And I also haven't yet found out how to set the cacheTime aspect.
Can anyone post a working example how to set the cacheTime aspect programmatically in Thingworx 8.5?
Has the above bug been fixed in Thingworx 9?