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

Community Tip - If community subscription notifications are filling up your inbox you can set up a daily digest and get all your notifications in a single email. X

How To Set Group in runtime through service under Resources->InfotableFunctions-> Services->TOJSON

MM_10159448
10-Marble

How To Set Group in runtime through service under Resources->InfotableFunctions-> Services->TOJSON

I Want to set group name programmatically through service of Resources->InfotableFunctions-> Services->TOJSON

I need standard service code to do programmatically.

 

Please check the below screen shot

MM_10159448_0-1707309301576.png

 

MM_10159448_1-1707309324668.png

 

 

ACCEPTED SOLUTION

Accepted Solutions

I have implemented code similar to this, but getting error of push related as shown in below image.

MM_10159448_0-1707389381671.png

from where data is getting in permissions highlighted below in bold

 

currentPermissions.permissions.push(newPermissions)

 

Pls send me root cause o this issue

 

View solution in original post

6 REPLIES 6

@MM_10159448 ,

 

I think this post should help you: https://community.ptc.com/t5/ThingWorx-Developers/How-to-AddRuntimePermission-for-PlatformSubsystem-amp/td-p/727025

 

In summary, run GetRuntimePermissionsAsJSON, append your own permissions to it, and then run SetRuntimePermissionsAsJSON

 

- Nick

Thank you for your reply,

 

I have viewed your provided link and code but in that code , Code is getting permission and then setting runtime permission for all who is falling under 

but my requirement is , I want to set group name for runtime for particular service only 'Resources->InfotableFunctions-> Services->TOJSON'(to this service only)

 

Please suggest any code for this

It would look something like this:

// result: JSON
var currentPermissions = JSON.parse(Resources["InfoTableFunctions"].GetRunTimePermissionsAsJSON());

var newPermissions = {

	"resourceName": "ToJSON",
	"EventSubscribe": [],
	"PropertyWrite": [],
	"PropertyRead": [],
	"ServiceInvoke": [{
		"isPermitted": true,
		"name": groupToAdd,
		"type": "Group"
	}],
	"EventInvoke": []
};

currentPermissions.permissions.push(newPermissions);

Resources["InfoTableFunctions"].SetRunTimePermissionsAsJSON({
	permissions: currentPermissions /* JSON */
});

 

Where groupToAdd is the name of the group you want to give access to that service.

 

-- Nick

I have implemented code similar to this, but getting error of push related as shown in below image.

MM_10159448_0-1707389381671.png

from where data is getting in permissions highlighted below in bold

 

currentPermissions.permissions.push(newPermissions)

 

Pls send me root cause o this issue

 

This is my below developed. Pls check any issue in this

function () {
    "use strict";
    try{   
    var jsonStringRuntime ='{"permissions":[{"resourceName":"*","PropertyRead":[],"PropertyWrite":[],"EventInvoke":[],"EventSubscribe":[],"ServiceInvoke":[]},{"resourceName":"GetClientApplicationKey","ServiceInvoke":[{"name":"ComposerUsers","type":"Group","isPermitted":true}]},{"resourceName":"GetClientNonce","ServiceInvoke":[{"name":"ComposerUsers","type":"Group","isPermitted":true}]},{"resourceName":"GetEntityList","ServiceInvoke":[{"name":"ComposerUsers","type":"Group","isPermitted":true}]},{"resourceName":"ReadEntityAsJSON","ServiceInvoke":[{"name":"ComposerUsers","type":"Group","isPermitted":true}]},{"resourceName":"ToJSON","ServiceInvoke":[{"name":"PASSUser","type":"Group","isPermitted":true}]}]}';   
    var currentPermissions = JSON.stringify(Resources["InfoTableFunctions"].GetRunTimePermissionsAsJSON());
    logger.warn("Get Permissions:"+currentPermissions);
    var newPermissions = {
    "EventSubscribe": [],
            "PropertyWrite": [],
            "PropertyRead": [],
            "ServiceInvoke": [
                {
                    "isPermitted": true,
                    "name": "PASSUser",
                    "type": "Group"
                }
            ],
            "resourceName": "ToJSON",
            "EventInvoke": []
        };
var mm=currentPermissions.permissions.push(newPermissions);
        logger.warn("Push Permissions:"+mm);
      Resources["InfoTableFunctions"].SetRunTimePermissionsAsJSON({
      permissions: mm /* JSON */
        });       
    }
    catch(err){
        logger.error("Error @ Thing -"+me.name+", testPerms, @ line " + err.lineNumber + ": " + err );
    }
}());

You're getting that error because you're parsing your JSON to a string with JSON.stringify().. Instead use JSON.parse().. You shouldn't have to use the parse function because that service returns a JSON but occasionally ThingWorx throws an error with JSON properties and service inputs so I always use the JSON.parse() function.   Also, I see you marked your last reply as the solution to the issue.  You may want to undo that as you haven't resolved your issue yet.

 

- Nick

Announcements


Top Tags