Community Tip - When posting, your subject should be specific and summarize your question. Here are some additional tips on asking a great question. X
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
Solved! Go to Solution.
I have implemented code similar to this, but getting error of push related as shown in below image.
from where data is getting in permissions highlighted below in bold
currentPermissions.permissions.push(newPermissions)
Pls send me root cause o this issue
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.
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