Clear the Assigned to field when the Assignment Group changes

vigo
Kilo Explorer

I am trying to using a onChange Client Script to clear the value of the Assigned To field when the Assignment Group changes. I tried to use the one that was posted on the messages, but it is not working.

Here is what I have:

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

if (isLoading) {  

return;  

}  

 

if (newValue == ''){

g_form.setValue('assigned_to','');

 

}      

}

This is not working, any suggestions?

1 ACCEPTED SOLUTION

Pradeep Sharma
ServiceNow Employee
ServiceNow Employee

Hi Vinay,



Below script will blank out the assigned_to field when the assignment group changes.


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


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


  return;


  }


  var assGrp = g_form.getControl('assignment_group');


  if(assGrp.changed)


  {


  g_form.setValue('assigned_to','');


  }


  //Type appropriate comment here, and begin script below



}


View solution in original post

22 REPLIES 22

Hi All,



I have the same issue and I would like to apply this change to one particular Catalog Item.   Can I do this by selecting sc_req_item Table?


You can write a catalog client script there you have a option to apply it to a particular catalog item.



Mark Correct if it solved your issue or hit Like and Helpful if you find my response worthy.


Thanks,
Deepa





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


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


return;  


  }  


var assGrp = g_form.getControl('assignment_group');  


if(assGrp.changed)  


  {  


  g_form.setValue('assigned_to','');  


  }  


}  


find_real_file.png


Hi Suraj,



Could you please give me the steps where I can implement this code.


I see people still need help with this although it's an old question. Just found an easier (less coding) way to do it.



Steps are as follows:



  • System Definition > Client Scripts > New > Name = Clear Assigned to > Table = Incident [incident] or Catalog Task (depending on which table you need this to work on) > Type = onChange > Field name = Assignment group > Description = "This script will clear the assigned to field when the assignment group changes" > Script :



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


if (isLoading) {


return ;


}



if (g_form.getValue('assigned_to') != '') {


g_form.setValue('assigned_to', '', '');


}


}



I found this script somewhere on community or wiki can't remember exactly but it works perfectly.



I also had the issue where I needed the "Assigned to" to only be available for write after the Assignment group has been chosen. UI Policy as follows:




  • System UI > UI Policies > New > Table = Incident or Catalog Task > Conditions > Assignment group = is empty > Right click header and Save > At bottom of page > UI Policy Actions > New > Read only = true > Field Name = Assigned to > Submit


This worked for me. I'll note in case anyone else wants to do it this way, I actually associated the client script with the 'Task' table and then selected the 'Inherited' box to ensure it works on all extensions of the Task table (incidents, sc_task, problem, etc.). I wanted this to work universally (see below for my *final* version).


find_real_file.png



Thank you everyone!