Skip to main content
10-Marble
February 7, 2024
Solved

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

  • February 7, 2024
  • 1 reply
  • 1919 views

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

 

 

Best answer by MM_10159448

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

 

1 reply

17-Peridot
February 7, 2024

@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

10-Marble
February 7, 2024

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

17-Peridot
February 7, 2024

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