- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-04-2020 07:59 AM
Hi All,
I have a requirement, If Opened by user is part of an Assignment Group then a responded checkbox should be default checked. I thought to using OnChange() client script using GlideAjax . Can anyone help me how to do it?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-06-2020 09:01 PM
As some have suggested, a Business Rule would be the best way to go, and because you're looking at the Opened by user, which is set on insert, an Advanced Before Insert Business Rule will do the trick. No need for it to run on update:
Here's the "Condition" field contents:
gs.getUser().isMemberOf("MediaFirst SRO Team")
And the "Script" field contents (you may have to change the field name):
(function executeRule(current, previous /*null when async*/) {
//set the Responded field to "true"
current.u_responded = true;
})(current, previous);
The reason your After Business Rule was not working is because you did not actually update the record. You do not need to, nor should you, include the update() function when using a Before Business Rule. And because you want to trigger an SLA or not based on the Responded field value, you are better off setting it before the insert of the record.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-04-2020 08:06 AM
Hi
Suggest you put this in a Business Rule rather than a client script.
You can then do an after/insert rule to check the logic and amend the record as required.
Cheers
Mike
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-06-2020 03:46 PM
Hi Mike,
You're right! I have to use BR.. But its not working as expected.As "responded" check box is connected with Response SLA.So when "Opened by" user belongs to particular group then Responded check box to be checked(Response SLA will work when Responded check box will be checked.
I wrote After/Insert BR but Responded check box is not getting active
var usr = gs.getUser().isMemberOf('MediaFirst SRO Team');
var grp = new GlideRecord('incident');
grp.addQuery('group.name', 'MediaFirst SRO Team');
grp.addQuery('opened_by', usr);
grp.addQuery();
if(grp.next()){
current.setValue('u_responded', 'true'); //Do something
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-04-2020 08:30 AM
For onchange of assignment group:
1) You can use code from User Object Cheat Sheet:
https://www.servicenowguru.com/scripting/user-object-cheat-sheet/
//Check to see if assigned to is a member of selected group
var grpName = 'YOURGROUPNAMEHERE';
var usrID = g_form.getValue("opened_by");
var grp = new GlideRecord('sys_user_grmember');
grp.addQuery('group.name', grpName);
grp.addQuery('user', usrID);
grp.query(groupMemberCallback);
function groupMemberCallback(grp){
//If user is a member of selected group
if(grp.next()){
//Do something
alert('Is a member');
}
else{
alert('Is not a member');
}
}
2) Write glideajax, check this one:
- If you want this only onload, use below approach:
Using Scratchpad variables in onDisplay Business rules along with Onload client script.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-06-2020 04:05 PM
Hi Gowrisankar,
I have tried option given by you.. "Responded" checkbox is getting checked but the Response SLA is not activated as Response SLA is activated when Responded check box will checked.May be server in script include we need to add it.But i don't know how?
I wrote Client Script using GlideAjax but Responded SLA didn't activated as Responded check box is active.
Client script-
function onLoad() {
var usrID = g_form.getValue("opened_by");
var ga = new GlideAjax('Responded');
ga.addParam('sysparm_name','checkIsMember');
ga.addParam('sysparm_user', usrID);
var ans = ga.getXMLWait();
g_form.setValue('u_responded',ans);
}
Script Include-
checkIsMember: function(){
var user1 = this.getParameter('sysparm_user');
var a=gs.getUser().isMemberOf('4b4f1266dbe023c0ca1e2ded0b961989');
return a;
},