If I understand correctly you want to remove the user role 'CurrentRole’ from all users except for one? Maybe it is easier to create a microflow that retrieves all users that have that UserRole and remove this role?
You can retrieve System.UserRole with id = ‘[%CurrentRole%]’ and all associated users. Then you can iterate over this list and remove the role 'CurrentRole’ from the association for every user (except for the one you want to keep). I hope this helps
I don't think you need Administration.Account as input for your first microflow.
1)You can first do a retrieve on database of UserRole with [id = '[%UserRole_CurrentRole%]'] (select range option first) → This gives you the UserRole to remove
2)Then you can retrieve all System.User over association from the UserRole you just retrieved. → This gives you all users that have that role
3)Then you can loop over the userList and change the association userRoles, where you remove UserRole (that you retrieved in step 1)
4)Commit the userList
In the first step you retrieve a list of userRole → select for the option range ‘First’:
In Step 2 you do : Retrieve list of $currentUser/UserRoles by association
With this retrieve you retrieve all userroles of your current user.
However, you want to retrieve all users that have the role ContactCentreAgentList. So you should retrieve list of $ContactCentreAgentList_UserRoles by association. Let's call this UserList
NEXT
iterate over UserList (IteratorUser) and remove the UserRole
Next
Commit the userList:
OK so a button that calls a microflow
Microflow has an Administration.Account (created) input
I then do a retrieve by association on user role CurrentRole
Then do I use a loop with a Change List > Clear or Remove option? Or use the Delete Object option?
Or is it better to do a retrieve from database with XPath?
[System.UserRoles/System.UserRole/Name = 'ContactCentreAgent'] for example...
Doesn't seem to be working for me...
Retrieve system.UserRole with XPath:
[id = '[%UserRole_ContactCentreAgent%]']
Outputname = 'ContactCentreAgentList'
NEXT
Retrieve list of $currentUser/UserRoles by association
Outputname = 'UserRoleList'
(not sure what you mean by 'retrieve all System.User over association from the UserRole you just retrieved')
NEXT
Iterate through UserRoleList (IteratorUserRole)
Change list entity:
Variable name = UserRoleList
Value = $IteratorUserRole
Type = Remove
NEXT IN LOOP
Commit UserRoleList
Without events
Refresh in client
NEXT
Exit loop and finish microflow