query on sys_user_grmember table not working

priya149
Mega Contributor

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';
}
}

1 ACCEPTED SOLUTION

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';
}
}

 

View solution in original post

12 REPLIES 12

Harsh Vardhan
Giga Patron

what is the exact requirement you have ? 

try now the  below script in workflow and let me know the log details.

 

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');
gr.addQuery('user',usr);
gr.query();
gs.log("RowCount is: "+gr.getRowCount());
if(gr.next()) {

return 'yes';
}
else{
return 'no';
}
}

Req is - If member of 1st level approval group is raising the request, approval should directly go to 2nd level approval group ,

for that i have added If activity before 1st level approval group activity to check and send in yes ,no.

below script will check if the u_caller_id user exist in any group then it will fulfill the if block , if not then else block. 

 

try with below script. and check the logs as well. 

 

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');
gr.addQuery('user',usr);
gr.query();
gs.log("RowCount is: "+gr.getRowCount());
if(gr.getRowCount() > 0) {

return 'yes';
}
else{
return 'no';
}
}

Hello value is coming in  rowcount and returning yes but its returning yes for all users who are in caller field,

I need to filter with groupname to fulfill my request. and its still not working.

gr.addQuery('name','abc');