Skip to main content
6-Contributor
March 19, 2024
Solved

Is it possible to use service to assign users to a particular group.

  • March 19, 2024
  • 2 replies
  • 1105 views

Would like to know if the below service can be called to assign members to the user group. I am getting error saying members is null when try to execute it. 

/Thingworx/Groups/Sample_Group/Services/AssignMembers.

Can give code snippet for the same?

Best answer by Velkumar

Hi @SK_9989757 

 

To add multiple users or usergroup

// CreateInfoTableFromDataShape(infoTableName:STRING("InfoTable"), dataShapeName:STRING):INFOTABLE(Principal)
let result = Resources["InfoTableFunctions"].CreateInfoTableFromDataShape({
 infoTableName: "InfoTable",
 dataShapeName: "Principal"
});
 
result.AddRow({name: "USER1", type : "User"});
result.AddRow({name: "UUSERGROUP1", type : "Group"});
 
Groups["USERGROUP"].AssignMembers({
	members: result /* INFOTABLE {"dataShape":""} */
});

 

If you are trying to do this via REST API, your request body should be

{
	"members": {
		"rows": [
			{
				"name": "USER1",
				"type": "User"
			},
			{
				"name": "UUSERGROUP1",
				"type": "Group"
			}
		],
		"dataShape": {
			"fieldDefinitions": {
				"name": {
					"name": "name",
					"aspects": {
						"isPrimaryKey": true
					},
					"description": "Principal name",
					"baseType": "STRING",
					"ordinal": 0
				},
				"type": {
					"name": "type",
					"aspects": {
						"isPrimaryKey": true
					},
					"description": "Principal type",
					"baseType": "STRING",
					"ordinal": 0
				}
			}
		}
	}
}

 /VR

2 replies

15-Moonstone
March 19, 2024
Groups[<USERGROUP>].AddMember({
	member: undefined /* STRING */,
	type: undefined /* STRING <-- "User" or "Group" */
});
Velkumar19-TanzaniteAnswer
19-Tanzanite
March 19, 2024

Hi @SK_9989757 

 

To add multiple users or usergroup

// CreateInfoTableFromDataShape(infoTableName:STRING("InfoTable"), dataShapeName:STRING):INFOTABLE(Principal)
let result = Resources["InfoTableFunctions"].CreateInfoTableFromDataShape({
 infoTableName: "InfoTable",
 dataShapeName: "Principal"
});
 
result.AddRow({name: "USER1", type : "User"});
result.AddRow({name: "UUSERGROUP1", type : "Group"});
 
Groups["USERGROUP"].AssignMembers({
	members: result /* INFOTABLE {"dataShape":""} */
});

 

If you are trying to do this via REST API, your request body should be

{
	"members": {
		"rows": [
			{
				"name": "USER1",
				"type": "User"
			},
			{
				"name": "UUSERGROUP1",
				"type": "Group"
			}
		],
		"dataShape": {
			"fieldDefinitions": {
				"name": {
					"name": "name",
					"aspects": {
						"isPrimaryKey": true
					},
					"description": "Principal name",
					"baseType": "STRING",
					"ordinal": 0
				},
				"type": {
					"name": "type",
					"aspects": {
						"isPrimaryKey": true
					},
					"description": "Principal type",
					"baseType": "STRING",
					"ordinal": 0
				}
			}
		}
	}
}

 /VR