Community Tip - When posting, your subject should be specific and summarize your question. Here are some additional tips on asking a great question. X
I'm trying to access and change the "Category" field for Properties on a Thing by using a script. I'd like to be able to set the Category for many Properties at once rather than having to type it in to each individual one.
Is there a way to do this?
Solved! Go to Solution.
Hi @Ascherer17 I see that the API does contain setCategory method as part of the class PropertyDefinition .
Couldn't locate any OOTB available service in Composer under the Thing itself ?
I couldn't find any service to set category besides AddPropertyDefinition. In my case though, the Properties will already be created, so this service will not work.
Thanks
Hi @Ascherer17 here's a workaround I could test successfully, its bit ugly but does the job. Basically i first delete the property definition and then I add property definition with the required category type using OOTB services to delete and create property definition.
Note : proprname is an input created and required for the service to lookup the property name
if (propname === null) { logger.error("valid property name required"); } else { var params = { name: propname /* STRING */ }; // result: INFOTABLE dataShape: "PropertyDefinition" // not must but could do this in order to get and hold on to the values from the existing property and assign them when the property will be recreated later var result = me.GetPropertyDefinition(params); logger.debug("printing out the result" + result); } try { var params = { name: propname /* STRING */ }; me.RemovePropertyDefinition(params); // removes the definition, effectively the entire property me.RestartThing(); // restart thing to reflect change logger.info("successfully removed the prop definition"); } catch (err) { logger.error("Failed to remove prop definition" + err); } // now i recreate the property with new definition including new category value try { var params = { defaultValue: undefined /* STRING */, remoteBindingAspects: undefined /* JSON */, description: "demo prop created from service" /* STRING */, readOnly: false /* BOOLEAN */, type: "BOOLEAN" /* BASETYPENAME */, remote: false /* BOOLEAN */, remotePropertyName: undefined /* STRING */, timeout: undefined /* INTEGER */, pushType: undefined /* STRING */, dataChangeThreshold: undefined /* NUMBER */, logged: false /* BOOLEAN */, name: propname /* STRING */, pushThreshold: undefined /* NUMBER */, dataChangeType: undefined /* STRING */, category: "booleanProperty" /* STRING */, persistent: true /* BOOLEAN */, dataShape: undefined /* DATASHAPENAME */ }; me.AddPropertyDefinition(params); me.RestartThing(); // require to reflect changes logger.info("Successfully added prop definition"); } catch (err) { logger.error("Failed to set prop definition " + err); }
Quick update: enhancement jira has been filed for this and status of which can be tracked in the knowledge base article Is there a setCategory() for programatically setting the Category for an entity's property in ThingWorx Composer