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

Community Tip - You can Bookmark boards, posts or articles that you'd like to access again easily! X

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

SK_9989757
5-Regular Member

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?

1 ACCEPTED SOLUTION

Accepted Solutions

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" */
});

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

Top Tags