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

Community Tip - Have a PTC product question you need answered fast? Chances are someone has asked it before. Learn about the community search. X

Programatically assign permissions to things

EM_9923519
12-Amethyst

Programatically assign permissions to things

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:

 

q33.png

 

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

 

 

 

 

2 REPLIES 2
PaiChung
22-Sapphire I
(To:EM_9923519)

You would have to do an iteration.

slangley
23-Emerald II
(To:EM_9923519)

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

Top Tags