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

Community Tip - Need help navigating or using the PTC Community? Contact the community team. X

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

SK_9989757
6-Contributor

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

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?

ACCEPTED SOLUTION

Accepted Solutions
Velkumar
19-Tanzanite
(To:SK_9989757)

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

View solution in original post

2 REPLIES 2
DanZ
15-Moonstone
(To:SK_9989757)

Groups[<USERGROUP>].AddMember({
	member: undefined /* STRING */,
	type: undefined /* STRING <-- "User" or "Group" */
});
Velkumar
19-Tanzanite
(To:SK_9989757)

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

Announcements


Top Tags