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

Community Tip - New to the community? Learn how to post a question and get help from PTC and industry experts! X

Add Run Time Permissions through script to Thing Templates, Thing Shapes, etc.

IPA
10-Marble
10-Marble

Add Run Time Permissions through script to Thing Templates, Thing Shapes, etc.

Hi,

I am trying to add Run Time permissions to various entities through script using the code snippet below. While I can add Run Time permissions to Things without any problems, I get errors when trying to set the Run Time permissions "PropertyRead", "PropertyWrite", "EventInvoke" and "EventSubscribe" for everything except for Things (i.e. ThingTemplates, ThingShapes, etc.). The error reads: "Execution error in service script MyThing AddPermissionsToThingTemplate] : Wrapped java.lang.Exception: This entity does not support property/event permissions Cause: This entity does not support property/event permissions". Surprisingly, the "ServiceInvoke" permission does not return an error and can be set.

var params = {

    principal: "MyGroup",

    allow: "true",

    resource: "*" ,

    type: "PropertyRead",

    principalType: "Group"

};

ThingTemplates[thingName].AddRunTimePermission(params);

How can I add Run Time permissions to entities that are not Things, e.g. Thing Templates and Thing Shapes, via script?

I am running ThingWorx 8.0.1-b39.

Thanks

4 REPLIES 4
liliu
8-Gravel
(To:IPA)

Hi Ioannis,

I suggest to use AddInstanceRunTimePermission for your scenario.

The code sould be something like this:

If you have any furhter concern, please feel free to let me know.

BR,

Lily

IPA
10-Marble
10-Marble
(To:liliu)

Hi Lily and thank you for your reply. The code you posted adds Run Time Instance Permissions, i.e. permissions that get inherited to the Things that are created from the Thing Template. However, what I want to do is to add Run Time Permissions to the Thing Template itself (and, later, also to other types of entities such as Thing Shapes, Data Shapes, Mashups, etc.).

liliu
8-Gravel
(To:IPA)

Hi Loannis,

As below screenshots shows, the properties and Events are empty. It means we couldn't grant ThingTemplate/ThingShape any run time permission that related to property and event.

ThingTemplate/ThingShape don't have specific values for properties and events, that why you can only grant the PropertyRead and PropertyWrite with Run Time Instance.

The reason why you can grant service execute is because ThingTemplete/ThingShape has some service that will be executed on their own entity like GetImplementingThings, GetImplementingThingsWithData...

As a conclusation, ThingTemplate/ThingShape AddRunTimePermission service only can grant service exectue permission.

Any concern, just let me know.

Best Regards,

Lily

mnarang
17-Peridot
(To:IPA)

Hi Ioannis,

ThingTemplate are not property providers they just hold the definitions .Template's do not store any data .Thus the correct service as mentioned in the above reply is AddInstanceRunTimePermission instead of AddRunTimePermission  . This service will through the error as mentioned by you when you will execute it on Template .Template do not hold actual values ,they are for defining the metadata .

If you are in a use case of using this service on Template then give details about the use case .But this is how it should work .

Thanks

Mukul Narang

Top Tags