- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-04-2020 07:52 AM
Hi All,
I want to add a single user into multiple group through catalog item. For which I have an item on which the user name is selected and the multiple groups are selected through list collector. I want to add the name of the group into the description field on the approval that is sent. For that I have created a event that is triggered when every approval is sent, into the event I am passing the Requests sysid and the name of the group for which the approval is sent. After that there is action action that is calling the approval table and adding the group name into it from the event.
The script is working fine and I am getting the correct value but only if one group is selected onto the list collector. When there are multiple group selected either they get one of the group name or it does not take group name in description.
Below is the snippet of the code to sent the approval from workflow:
// Set the variable 'answer' to a comma-separated list of user ids and/or group ids or an array of user/group ids to add as approvers.
//
// For example:
// answer = [];
// answer.push('id1');
// answer.push('id2');
var answer = [];
var groups = current.variables.add_users_groups.toString();
var listArr = groups.split(',');
for (var i=0;i<listArr.length;++i) {
var group = new GlideRecord('sys_user_group');
group.addQuery('sys_id',listArr[i]);
group.query();
if(group.next()){
var mgrID = group.manager;
answer.push(mgrID.toString());//push manager
gs.eventQueue("description.addition",current,current.sys_id,group.name);
//answer.push(group.sys_id.toString());
//gs.sleep(20000);
}
}
Below is the script written in my script action:
var sysId = event.parm1.toString();
gs.log("RITM Sys id is "+sysId);
var glide = new GlideRecord("sysapproval_approver");
glide.addEncodedQuery('sysapproval='+sysId+'^state=requested^u_descriptionISEMPTY');
glide.query();
gs.log("Row count is "+glide.getRowCount());
while(glide.next()) {
gs.log("inside loop");
var grpName=event.parm2;
gs.log(grpName);
glide.setValue('u_description',event.parm2);
glide.update();
}
Can anyone help me so that all the approval sent have the name of the group for which it is sent?
Thanks
Devina
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-05-2020 05:04 AM
Hi,
Are they stuck from long ago or only few mins? If few mins, then could be due to gs.sleep.
I think the better way to fix this is liek this
1. remove gs.sleep from script action
2. In the code, where you are triggering the event.. trigger it like this
// For example:
// answer = [];
// answer.push('id1');
// answer.push('id2');
var answer = [];
var groups = current.variables.add_users_groups.toString();
var listArr = groups.split(',');
var gdt = new GlideDateTime();
gdt.addSeconds(60);
for (var i=0;i<listArr.length;++i) {
var group = new GlideRecord('sys_user_group');
group.addQuery('sys_id',listArr[i]);
group.query();
if(group.next()){
var mgrID = group.manager;
answer.push(mgrID.toString());//push manager
gs.eventQueueScheduled("description.addition",current,current.sys_id,group.name,gdt);
//answer.push(group.sys_id.toString());
//gs.sleep(20000);
}
}
if stuck from long time, go to active transactions and check if anything got stuck and kill it.
Mark the comment(s) as helpful if they are helping to solve the problem.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-05-2020 09:24 AM
Hi Asifnoor,
Its working as expected only problem is that the last approval is not getting the group name.
Thanks
Devina

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-05-2020 09:29 AM
Strange. In the Script Action check if the code is entering into this if conditon for all approvals or not.
if(currentUser.isMemberOf(Âevent.parm2.toString())) {
Add 1 log above this if condition and check.
gs.log("Approver: "+glide.approver+" group name: "+event.parm2.toString());
Mark the comment as helpful if this helps.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-05-2020 10:22 AM
Hi Asifnoor,
Its working as expected now. I killed the jobs running and it started working.
Thanks! A lot for your help 🙂
Regards
Devina