- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-14-2014 03:05 AM
Hi Guys/Girls.
I know this is possible as it was set up like this in my old job but only been working with Service Now admin for a few weeks now so still very new to all of these java scripts etc.
Anyway, In an active incident, if the incident is re-assigned from one Assignment group to another, I want it to automatically remove the Assigned To user. At the moment, we're receiving incidents back from 2nd Line IT to the Service Desk and the incident is still showing as assigned to their engineers (which aren't even in the Service Now assignment group to begin with!)
Any advice would be really appreciated. I would imagine I have to create a Client Script of some sort, possibly onCellEdit or onChange but not sure which and not sure what content to include.
Thanks a lot.
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-14-2014 05:17 AM
Hi Mark,
I think I understand your requirement now.
If you want the script to only run on existing Incidents (records which have been saved at least once), you could use:
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue == '') {
return;
}
if(!g_form.isNewRecord()){ // clear assigned_to because assignment group just changed, on an existing record
g_form.clearValue('assigned_to');
}
}
However, if you don't want the value to be cleared for the Service Desk users, you might need some more specific logic. For example, you could check which group has been selected, and then decide if you want to clear the Assigned To. The code below checks the display value of the Assignment Group, and bypasses the clearValue if the group display name is "Service Desk".
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue == '') {
return;
}
var groupName = '';
if(g_form.getDisplayBox('assignment_group')) groupName = g_form.getDisplayBox('assignment_group').value; // get display value of group
if(!g_form.isNewRecord() && groupName!='Service Desk'){ // clear assigned_to because assignment group just changed to something other than Service Desk, on an existing record
g_form.clearValue('assigned_to');
}
}
Let me know if this works for you?
Regards,
Jake
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-14-2014 06:11 AM
Looks like I was right 🙂 You need to change the Field Name field to Assignment Group, not Assigned To. Then Jake Gillespie's script will work fine.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-14-2014 06:23 AM
You can also put in if(newValue=='Service Desk') if your requirement is actually from second line back to the Service Desk.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-14-2014 06:26 AM
Amazing stuff guys! Thank you so much. Just ran a few tests and that's working exactly how we need it to.
Million thanks!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-14-2014 03:18 PM
Hi Mark,
That is great to hear. As Adam pointed out, you need select the field for which the onChange script will be triggered. In your case this needed to be Assignment Group. I'm glad the script is working now!
Mike - the Assignment Group field is a reference field, not a string/choice field. That means the value (which newValue would hold in an onChange script) would be the sys_id of the referenced record, and not the display value (e.g Service Desk). We could have hard coded the sys_id into the script, however this goes against best practice and would potentially cause issues when the code is migrated between instances (e.g Dev->Test) if the "Service Desk" group had different sys_id values. Even using the method we've adopted here, we have hard coded the display value of the group. To be most flexible, a system property should be defined with the display value of the group (or groups) required for the script. Then, in an onDisplay Business Rule, this value could be retrieved using gs.getProperty() and then copied to the g_scratchpad. The onChange client script could then refer to the g_scratchpad value etc. By using this method, an admin would not need to change the client script when and if the group name for "Service Desk" changes as they could simply update the system property.
Regards,
Jake

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-23-2019 06:22 AM
Hi