- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-28-2020 06:38 AM
I have a requirement For Record producer ,if 1st level Group approver is raising a request, approval should go to the 2nd level approval.
I have written one If condition as below but it seems query on group name is not working can someone correct me if anything wrong-
answer = ifScript();
function ifScript() {
var usr = current.u_caller_id;
gs.log('Test1' + usr); // sysid of caller is coming
var gr = new GlideRecord('sys_user_grmember');
gs.log('Test2' + gr);//logs coming
// Tried below all commented query but Rowcount log is not coming
//gr.addQuery('group.name','d6f05a17dbad08909acafd651d961960');
//gr.addQuery('group.name','ABC');
//gr.addQuery('group', ABC);
//gr.addEncodedQuery('group=d6f05a17dbad08909acafd651d961960^');
//gr.addEncodedQuery('user='+usr+'^group.name=ABC');
gr.addQuery('user',usr);
gr.query();
if(gr.next()) {
gs.log("RowCountanu:"+gr.getRowCount());
return 'yes';
}
return 'no';
}
On backgrpund script getting the rowcount
Also tried below code-
answer = ifScript();
function ifScript() {
var appr="";
var usr = current.u_caller_id;
var grp = new GlideRecord('sys_user_group');
grp.addQuery('name','Solution Owner Group');
grp.query();
if(grp.next()) {
var gm = new GlideRecord('sys_user_grmember');
gm.addQuery('group',grp.sys_id);
gm.query();
while(gm.next()) {
gs.log("RowCountanu:"+gm.getRowCount()); // not coming
appr = gm.user.sys_id;
if(appr == usr)
{
return 'yes';
}
return 'no';
}
}
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-29-2020 02:57 AM
try now.
answer = ifScript();
function ifScript() {
var appr="";
var usr = current.u_caller_id
var gm = new GlideRecord('sys_user_grmember');
gm.addQuery('group.name','abc');
gm.addQuery('user',usr);
gm.query();
gs.log("RowCountanu:"+gm.getRowCount()); // not coming
if(gm.getRowCount() >0) {
return 'yes';
}
else{
return 'no';
}
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-29-2020 02:57 AM
try now.
answer = ifScript();
function ifScript() {
var appr="";
var usr = current.u_caller_id
var gm = new GlideRecord('sys_user_grmember');
gm.addQuery('group.name','abc');
gm.addQuery('user',usr);
gm.query();
gs.log("RowCountanu:"+gm.getRowCount()); // not coming
if(gm.getRowCount() >0) {
return 'yes';
}
else{
return 'no';
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-29-2020 03:57 AM
It worked 🙂 Thanks for the help
mainly i was missing if(gr.getRowCount() > 0) condition.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-28-2020 06:47 AM
Hi Priya,
the workflow is on which table? since it is the record producer
check whether the value for field u_caller_id is coming or not?
var usr = current.u_caller_id;
gs.log('Test1 ' + usr); // sysid of caller is coming
Mark ✅ Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-28-2020 09:55 PM
Hello its on custom table. and value is coming for the user.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-28-2020 11:48 AM
Hi,
Script looks fine for me and also I ran the below script In background scripts - it is printing correct value.
I just made two changes
1. var usr = gs.getUserID(); instead of u_caller_id
2. Group name as "Architects" instead of "Solution Owner Group"
See if there are any Spaces in your group name.
answer = ifScript();
function ifScript() {
var appr="";
var usr =gs.getUserID();//current.u_caller_id
var grp = new GlideRecord('sys_user_group');
grp.addQuery('name','Architects');
grp.query();
if(grp.next()) {
var gm = new GlideRecord('sys_user_grmember');
gm.addQuery('group',grp.sys_id);
gm.query();
while(gm.next()) {
gs.log("RowCountanu:"+gm.getRowCount()); // not coming
appr = gm.user.sys_id;
if(appr == usr)
{
//return 'yes';
gs.print("yes");
}
gs.print("No");
//return 'no';
}
}
}
Thanks,
-Vinay