Alert when Changing the Category

GUPE
Kilo Explorer

Hi,  

I want a pop-up alert to be displayed when a users changes the Category and/or Subcategory to warn them that this will clear the description field.     I have created a client script with the…

1 ACCEPTED SOLUTION

Pradeep Sharma
ServiceNow Employee
ServiceNow Employee

Hi @Guy Peacock



I hope the below wiki link will answer your question If you are looking fields to be prepopulated based on other field


http://wiki.servicenow.com/index.php?title=Data_Lookup_and_Record_Matching_Support



Please mark your question as answered if it resolves your issue



Thanks


Pradeep Sharma


View solution in original post

8 REPLIES 8

Pradeep Sharma
ServiceNow Employee
ServiceNow Employee

Hi Guy Peacock



Try this "on change client script" on "Category"


Script:


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


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


          return;


    }


if(newValue != oldValue)


{


var answer = confirm("The category field on the form have changed.\nDo you really want to save this record?");


if (answer == true) {


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


return true;


}


else


{


return false;


}


}


    }




I hope this helps



Thanks


Pradeep Sharma




GUPE
Kilo Explorer

Hi Pardeep,



I am getting the pop up but there is not change to the category if i click OK or cancel.



Thanks for the help so far,



Guy


Pradeep Sharma
ServiceNow Employee
ServiceNow Employee

Hi @Guy peacock



The above script will clear the description field if you click OK.


Can you please let me know what is that exactly you are looking for.


Thanks in advance.



Best regards


Pradeep Sharma


Added one line in the above code:



g_form.setValue('category',oldValue);


Final Code :



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


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


          return;


  }


if(newValue != oldValue)


{


var answer = confirm("The category field on the form have changed.\nDo you really want to save this record?");


if (answer == true)


{


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


return true;


}


else


{


g_form.setValue('category',oldValue);


return false;


}


}


  }