- 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-28-2020 10:04 PM
not working in workflow.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-28-2020 01:11 PM
If you are using this within the Script field of a Record Producer then keep the following mind:
current refers to the record you are about to create. Typically you set values for current in the script of a record producer. Only fields that exist on the final record are included in current.
If you have a field that only exists on the record producer, you would access the value using producer.<variablename>.
Perhaps current.u_caller_id should be producer.u_caller_id ?
You might also try changing
if(grp.next()) { to
while(grp,next()) {
"if" should certainly work as long as you are getting back one result, but I have, on occasion, seen it make a difference.
If this was helpful, or correct, please be kind and click appropriately.
Michael Jones - Cloudpires
Michael D. Jones
Proud member of the GlideFast Consulting Team!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-28-2020 10:03 PM
Hello,
I have already tried with while as well.
u_caller_id is a field on table for which RP created, we don't have any variable on form.