- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-17-2017 01:26 AM
Have a requirement as below:-
Created a watchlist field(u_groups) to select many groups.
Condition is, if in selected group atleast one member has "approver" role then only the group should be selected else it should display the field name and message.
Any code will be helpful.
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-17-2017 08:58 AM
Hi Iqubal
1. you were looking to display some message when you are selecting the group name. For this you need to create a client script onChange.
2. What is current_u_groups ?? If you are looking for the current group value then it should be current.u_groups. but current does not work in the client script. you need to use g_form
3. You need to create a glideajax script. the client script will call that glide ajax. and the script which you have written will go in glide list. this glide list should return Yes or no or some other value.
4. then in your cliet script you can show this value in message
To understand about the glideajax please see the link - http://wiki.servicenow.com/index.php?title=GlideAjax#gsc.tab=0
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-17-2017 01:50 AM
HI
You can do this by having a on change client script on this field. In the client script get the selected group name and then glideRecord on the group member table "sys_user_grmember". Get all list of the users and check each users in the other table - "sys_user_has_role". on this table you can check if user have approver role or not. Based on the result you can display the message.
Regards
Harsh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-17-2017 08:42 AM
Hi harsh,
I got the script and it is working fine when I'm running in background script. But while using script include and calling it from reference qualifier it's doing nothing.
field u_groups is watchlist type.
var answer = [];
var groupMember = new GlideRecord('sys_user_grmember');
groupMember.addQuery('group', current_u_groups);
groupMember.query();
while(groupMember.next()){
var user_sys_id = groupMember.getValue('user');
var hr = new GlideRecord('sys_user_has_role');
hr.addQuery('user', user_sys_id);
hr.addQuery('role', 'e098ecf6c0a80165002aaec84d906014'); //sys_id of role
hr.query();
if(hr.next())
{
answer.push(groupMember.getDisplayValue('group'));
gs.print("Groups are "+answer);
}
else{
answer.push("");
gs.print("No Groups qualifies"+answer);
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-17-2017 08:58 AM
Hi Iqubal
1. you were looking to display some message when you are selecting the group name. For this you need to create a client script onChange.
2. What is current_u_groups ?? If you are looking for the current group value then it should be current.u_groups. but current does not work in the client script. you need to use g_form
3. You need to create a glideajax script. the client script will call that glide ajax. and the script which you have written will go in glide list. this glide list should return Yes or no or some other value.
4. then in your cliet script you can show this value in message
To understand about the glideajax please see the link - http://wiki.servicenow.com/index.php?title=GlideAjax#gsc.tab=0
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-17-2017 10:32 AM
Hi Iqubal,
you also need to return the values from script include,
add these lines to the final part of the function.
answer.join(",");
return "group.sys_idIN"+ answer;
}
Btw in your code you used,current_u_groups which is no where declared. Also, make sure to pass values from the reference qualifies like javascript: new Script().function(value to pass);
in the script retrieve it function zyx(variable){
}
One more thing:
use gs.addInfoMessage(); instead of print