Checking if reference field has any selections in it

codedude
Mega Expert

I have 2 reference fields, one is requester the other is requester group(s). The requester group gets filled with the requester's group(s). It is currently filling them with no problem, what I would like it to is to throw an alert to the window if the requester group(s) reference field does not any selections in it to select. In other words, if the requester currently is not in any groups, throw the message to the window, else do nothing....


This is the current scripting I have in my workflow in Additional Approvers Script section :


answer = [];  

var approvers = new GlideRecord('sys_user_grmember');  

approvers.addQuery('group', current.u_requestor_group.sys_id); //Assumption: u_requestor_group is not null

approvers.query();  

while(approvers.next()) {  

    if(approvers.user.toString() != current.requested_by.toString())

    {  

          answer.push(approvers.user.toString());  

    }  

}

Can anyone help me with this?

1 ACCEPTED SOLUTION

I think you need the users sys_id


try


var uID =   g_user.userID;



As the 'sys_user_grmember' tables user field is a reference field to the sys_user table


View solution in original post

8 REPLIES 8

try while(grmember._next())


Daryll,



That did not work... Could it be that I am pulling the username and not the full name? I am filtering on the user field, which from my knowledge displays the full name, not username. If that is the case, how do I pull the current users full name on page load?


I think you need the users sys_id


try


var uID =   g_user.userID;



As the 'sys_user_grmember' tables user field is a reference field to the sys_user table


If that doesn't work try changing



grmember.addQuery('user', uID);



to



grmember.addQuery('user.sys_id', uID);