- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-24-2015 05:52 PM
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?
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-25-2015 08:12 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-25-2015 06:52 AM
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());
}
}
if(answer.length == 0) // array length of zero indicates user is not in a single group
{
// you can populate message here
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-25-2015 06:56 AM
This can go in the workflow, doesn't have to be a client side script does it?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-25-2015 07:30 AM
Hi Josh,
Workflow scripting is server side so if you want to display some error message to end user, then it wont help.
You will have to write down either onChange or onSubmit catalog client script ( I assume you are working on catalog item) or onChange / onSubmit client script.
In that case, you will have to check if your variable / field does not contain a null value or it is not empty. If it is you can simply throw error or warning or alert message.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-25-2015 07:42 AM
Hi Deepak,
I ended up writing an onLoad client side script because I saw that the message would not be displayed until the change had been submitted. I need the message to appear on page load, so I need to check if the user is in any groups as the page is loading. End product is that the user can not submit a change ticket if they are not in a group. I scripted what I have below and it is messing up at the beginning of the while loop :
function onLoad() {
//Get the username of the current user
var uID = g_user.userName;
//Get all active groups where user is a member
var grmember = new GlideRecord('sys_user_grmember');
grmember.addQuery('user', uID);
grmember.addQuery('group.active', true);
grmember.query();
while(grmember.next()){
alert('User is in group(s)');
}
}
Any suggestions?