Remove Assigned to when call is re-assigned to a new Assignment group

markdgoahead
Kilo Explorer

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.

1 ACCEPTED SOLUTION

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


View solution in original post

14 REPLIES 14

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.


You can also put in if(newValue=='Service Desk') if your requirement is actually from second line back to the Service Desk.


Amazing stuff guys! Thank you so much. Just ran a few tests and that's working exactly how we need it to.



Million thanks!


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


Hi 

markdgoahead,
 
I'm new to scripting as well, and trying to achieve the same here with our new Instance.
I will try to follow what the guys suggested - I hope the script will run fine, 
 
Do you have the script that you used to solve the issue?
 
Thanks.