Community Tip - You can Bookmark boards, posts or articles that you'd like to access again easily! X
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:
The line
category: MyCategory" /* STRING */,
misses the opening quote?
Also the line
description: ''my desc"/* STRING {"defaultValue":""} */,
uses two different types of quote, single and double.
That happens during anonymising code. In original code, it's done correctly, if not - it would generate error.
Hi @ZbigniewK
If you want to copy all the property, you can use below code
// result: INFOTABLE dataShape: "PropertyDefinition"
let thing1PropertyInfoTable = Things["T"].GetPropertyDefinitions({
category: undefined /* STRING */,
type: undefined /* BASETYPENAME */,
dataShape: undefined /* DATASHAPENAME */
});
// status: INFOTABLE dataShape: "BulkProcessingReport"
let result = me.AddPropertyDefinitions({
ignoreInvalidDefinitions: true /* BOOLEAN */,
values: thing1PropertyInfoTable /* INFOTABLE */
});
To add specific properties
// result: INFOTABLE dataShape: "PropertyDefinition"
let result = Things["T"].GetPropertyDefinitions({
category: undefined /* STRING */ ,
type: undefined /* BASETYPENAME */ ,
dataShape: undefined /* DATASHAPENAME */
});
let propertyList = ["prop1", "prop2", "G"];
result.rows.toArray().forEach(jsonValue => {
if (propertyList.indexOf(jsonValue.name) !== -1) {
me.AddPropertyDefinition({
defaultValue: undefined /* STRING */ ,
remoteBindingAspects: undefined /* JSON */ ,
description: jsonValue.description /* STRING */ ,
readOnly: jsonValue.isReadOnly /* BOOLEAN */ ,
remote: undefined /* BOOLEAN */ ,
type: jsonValue.baseType /* BASETYPENAME */ ,
remotePropertyName: undefined /* STRING */ ,
timeout: undefined /* INTEGER */ ,
pushType: undefined /* STRING */ ,
dataChangeThreshold: undefined /* NUMBER */ ,
logged: jsonValue.isLogged /* BOOLEAN */ ,
name: jsonValue.name /* STRING */ ,
pushThreshold: undefined /* NUMBER */ ,
dataChangeType: undefined /* STRING */ ,
category: undefined /* STRING */ ,
persistent: jsonValue.isPersistent /* BOOLEAN */ ,
dataShape: undefined /* DATASHAPENAME */
});
}
});
Note : Run above script in View Only mode
/VR
Hi @ZbigniewK,
I wanted to see if you got the help you needed.
If so, please mark the appropriate reply as the Accepted Solution. It will help other members who may have the same question.
Please note that industry experts also review the replies and may eventually accept one of them as solution on your behalf.
Of course, if you have more to share on your issue, please pursue the conversation.
Thanks,