Needed to copy some properties from one Thing to other. To avoid manual work, created Service with AddPropertyDefinition (later wanted to add service to copy values). It creates no error when running first time, but properties are not generated. So, started script - and it answer "Property [name] already exists".
Manual refreshing of Thing in web service does not help. Restart Thing by code also makes no difference.
Here is sample code:
myList = me.GetPropertyDefinitions({
category: "MyCategory" /* STRING */,
type: undefined /* BASETYPENAME */,
dataShape: undefined /* DATASHAPENAME */
});
for each (var x in myList.rows) {
Things["MyThing"].AddPropertyDefinition({
indexed: undefined /* BOOLEAN {"defaultValue":false} */,
defaultValue: undefined /* STRING */,
remoteBindingAspects: undefined /* JSON */,
description: "my desc"/* STRING {"defaultValue":""} */,
readOnly: undefined /* BOOLEAN {"defaultValue":false} */,
type: 'INFOTABLE' /* BASETYPENAME */,
remote: undefined /* BOOLEAN {"defaultValue":false} */,
remotePropertyName: undefined /* STRING */,
timeout: undefined /* INTEGER {"defaultValue":0} */,
pushType: undefined /* STRING */,
accessModifier: undefined /* JSON */,
dataChangeThreshold: undefined /* NUMBER */,
logged: undefined /* BOOLEAN {"defaultValue":false} */,
name: x.name /* STRING */,
pushThreshold: undefined /* NUMBER */,
dataChangeType: undefined /* STRING */,
category: "MyCategory" /* STRING */,
persistent: true /* BOOLEAN {"defaultValue":false} */,
dataShape: 'myDataShape' /* DATASHAPENAME */
});
}
Things["MyThing"].RestartThing();
Things["MyThing"].EnableThing();