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

m_servicenow
Kilo Contributor

Mark,


You can see the below url for help with scripts. If still you are unable to get the solution then let me know:



http://wiki.servicenow.com/index.php?title=GlideForm_(g_form)#clearValue


markdgoahead
Kilo Explorer

Thanks for that, very helpful.



So it looks like I need to create an onChange Client Script. I'm a bit stuck on content (scripting is far from my strong point!).



I have:



function onChange(control, oldValue, newValue, isLoading, isTemplate) {


    if (isLoading || newValue == '') {


          return;


    }




    //Type appropriate comment here, and begin script below


   


}void clearValue(Assigned to)



So I've specified to clear everything in the Field "Assigned To" but will have to add a condition so it only does this when the Assignment Group is changed?



Any ideas on what to use?



Thanks.


Jake Gillespie
Mega Guru

Hi Mark,



Create a client script as type "onChange", then select the field name for it to act on (e.g Assignment Group). Then paste the following script into the script field:


function onChange(control, oldValue, newValue, isLoading, isTemplate) {


  if (isLoading || newValue == '') {


  return;


  }



  // clear assigned_to because assignment group just changes


  g_form.clearValue('assigned_to');



}



Regards,


Jake


Hi Jake.



Thanks for that, tested that but it's just automatically removing everything we enter into Assigned To field. Just to clarify, I need to set this up on existing incidents, so that if an Engineer from the 2nd line team has an incident assigned to them, when they change the assignment group back to Service Desk, it removes their name by default instead of leaving it in there.



Thanks a lot.