How to set value for priority based on another field (i.e., reference field) using client script

Nitesh Chandana
Kilo Expert

Hello,

I am not able to set value for the priority field based on the reference field(department). I created two fields department and priority. department is reference and priority is choice.

If i select customer support. priority should be changed to critical. if we select IT, priority should be changed to High.

My script is

var ge= g_form.getReference('group');

  if(ge.name == 'IT')

  {

  g_form.setValue('priority','2');

  g_form.setMandatory('emergency');

  }

Can anyone help me out??

Thanks,

NItesh

1 ACCEPTED SOLUTION

nthumma
Giga Guru

You have to get reference like below


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


    var caller = g_form.getReference('group', doAlert); // doAlert is our callback function


}


function doAlert(caller) { //reference is passed into callback as first arguments


  if (caller.name == 'IT')


    {


  g_form.setValue('priority','2');


  g_form.setMandatory('emergency');


}


}



View solution in original post

5 REPLIES 5

Pradeep Sharma
ServiceNow Employee
ServiceNow Employee

Hello Nitesh,



To add: Priority is auto calculated based on impact and urgency field. In this case, you will have to set the impact and urgency field.