Community Tip - Stay updated on what is happening on the PTC Community by subscribing to PTC Community Announcements. X
I have several lists of things that I want to assign visibility permission to a certain level of my organization
In this case MyOrganization->Root->Th->TT 1 and console user group to the runtime permission:
How can I do it programatically?
There is a snipet for run time:
var params = {
principal: undefined /* STRING */,
allow: undefined /* BOOLEAN */,
resource: undefined /* STRING */,
type: undefined /* STRING */,
principalType: undefined /* STRING */,
collectionName: undefined /* STRING */
};
// no return
Resources["CollectionFunctions"].AddCollectionRunTimePermission(params);
And a snippet for visibility
var params = {
principal: undefined /* STRING */,
principalType: undefined /* STRING */,
collectionName: undefined /* STRING */
};
// no return
Resources["CollectionFunctions"].AddCollectionVisibilityPermission(params);
How do I change the parameters to set these permissions to a list of things?
I have this script that will assign permissions based on array definition:
var thingsPermissions=[
{"Organization Level":"MyOrganization->Root->Th->TT 1","usergroup":"gr1","TheThings":['thing1', 'thing2',....] },
{"Organization Level":"MyOrganization->Root->Th->TT 2","usergroup":"gr2","TheThings":['other1', 'other2',...] },
....
];
try {
var result = "";
for (var i in thingsPermissions) {
//the level of the organization
var org = thingsPermissions[i]["Organization Level"];
//the user group that will have permissions
var usrGrp= thingsPermissions[i]["usergroup"];
//loop all the things and assign the organization and user group
for (var j in thingsPermissions[i]["TheThings"]) {
var currentThing = thingsPermissions[i]["TheThings"][j];
//////////HOW TO ASSIGN PERMISSIONS?
}
}
}
catch (err) {
logger.error("Service error in " + me.name + " at " + err.lineNumber +": " + err);
}
You would have to do an iteration.
Hi @EM_9923519
If you found the previous response to be helpful, please mark it as the Accepted Solution for the benefit of others with the same question.
Regards.
--Sharon