cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Your Friends List is a way to easily have access to the community members that you interact with the most! X

Change Property Category via Script

Ascherer17
14-Alexandrite

Change Property Category via Script

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?

1 ACCEPTED SOLUTION

Accepted Solutions
supandey
19-Tanzanite
(To:Ascherer17)

Yes the one i mentioned is what i found in the API doc, so I guess if you are developing an extension using ThingWorx Extension SDK, i think you should be able to create a custom service referencing that setCategory.

But yeah I also didn't find this in the composer (OOTB) , I'll look into it may be this can be entered as enhancement request.

View solution in original post

5 REPLIES 5
supandey
19-Tanzanite
(To:Ascherer17)

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 ? 

Ascherer17
14-Alexandrite
(To:supandey)

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

supandey
19-Tanzanite
(To:Ascherer17)

Yes the one i mentioned is what i found in the API doc, so I guess if you are developing an extension using ThingWorx Extension SDK, i think you should be able to create a custom service referencing that setCategory.

But yeah I also didn't find this in the composer (OOTB) , I'll look into it may be this can be entered as enhancement request.
supandey
19-Tanzanite
(To:Ascherer17)

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);

}

 

 

supandey
19-Tanzanite
(To:supandey)

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

Top Tags