Creating Workflow to add and remove users from assignment groups

aismail
Kilo Contributor

Hello All,

I am fairly new to ServiceNow and continuously learning new skills and techniques everyday. I have just begun working with Workflows and had a quick question. I am looking to build a slight automation process for users, and was wondering if anyone has experienced a similar build. You insight is much appreciated.

How i am thinking it should work:

1. Catalog item is created where users can request if they want to be removed or added to a group.

2. If they are requesting to be removed, it just automatically removes them (no approval)

3. If they are requesting to be added to a group, an approval is sent out to group manager

4. If group manager accepts, user is added to group and notification is sent out. If rejected then a notification is sent and request is closed.

Is there a better process/design? Any Technic or skills that would help? How would one automate the addition and removal of users? What would be a good place to start in regards to best practice and creating the workflow.

I have tried looking for online resources but couldn't find anything specific to assignment groups. If anyone knows of any resources available, that would be great!

Thanks

1 ACCEPTED SOLUTION

randrews
Tera Guru

i do it also... just a script to add a row to the table.. like below   the flush messages keeps the person who approves the record from seeing any add info messages triggered by the script... the current. comments updates the requested item with the note.



this is in a run script block after the mark as approved item.





addtogroup();



function addtogroup(){


    var newgrpmember = new GlideRecord('sys_user_grmember');


    newgrpmember.user = current.variable_pool.requested_for;


    newgrpmember.group = current.variable_pool.v_member_group_new;


    newgrpmember.update();


    gs.flushMessages();


    current.comments += '\n' + "Added to group " + newgrpmember.group.getDisplayValue();


    current.update();


}


View solution in original post

29 REPLIES 29

actually i take it back users can do this one.. so no need for a script triggered by an event.. the script to add to a group is...


_____________________________________________________________


addtogroup();



function addtogroup(){


    var newgrpmember = new GlideRecord('sys_user_grmember');


    newgrpmember.user = current.variable_pool.requested_for;


    newgrpmember.group = current.variable_pool.v_member_group_new;


    newgrpmember.update();


    gs.flushMessages();


    current.comments += '\n' + "Added to group " + newgrpmember.group.getDisplayValue();


    current.update();


}


_____________________________________________


the below will remove from ALL groups.. you can certainly modify it to query the table and only remove from ONE group...



______________________________________________


removefromgroup();



function removefromgroup(){


    var oldgroup= new GlideRecord('sys_user_grmember');


    oldgroup.addQuery('user',current.variable_pool.requested_for);


    oldgroup.query();


    while (oldgroup.next()){


          current.comments += "Removed from group " + oldgroup.group.getDisplayValue();


          oldgroup.deleteRecord();


          gs.flushMessages();


    }


}


_______________________________________________________




the flushMessages is not a command you see often.. it prevents the user that submits/approves the items from seeing the addinfo messages that are pending from the table add/remove.


Thank You Raymond, I was able to achieve the requirement with the changes in the script.



Now, that the request is automated, can you please suggest how can we proceed   with the closure of the Catalog Task once the request is completed, this has to be done too via automation, i tried with Set Value, but this is running on the Request Item Table and not on the Catalog Task Table.



Thank in advance


randrews
Tera Guru

i do it also... just a script to add a row to the table.. like below   the flush messages keeps the person who approves the record from seeing any add info messages triggered by the script... the current. comments updates the requested item with the note.



this is in a run script block after the mark as approved item.





addtogroup();



function addtogroup(){


    var newgrpmember = new GlideRecord('sys_user_grmember');


    newgrpmember.user = current.variable_pool.requested_for;


    newgrpmember.group = current.variable_pool.v_member_group_new;


    newgrpmember.update();


    gs.flushMessages();


    current.comments += '\n' + "Added to group " + newgrpmember.group.getDisplayValue();


    current.update();


}


One thing you may want to do   on your script... is to check to see if they already ARE a group member...



in our organization we ONLY allow people to be a member of ONE group at a time.. so the first thing this workflow does is remove the person from all groups... then it checks to see if there is an add to a new group <or just remove from all groups> and if there is an add it will add them to that group...



since i have already removed them from all groups i don't have to worry about duplicate entries on the table... and can just run the add script...


aismail
Kilo Contributor

Thank you Doug, this helps greatly.



Currently users can be added into more than one group, just for simplicity sake. I will definitely keep this in mind however if the requirements change.