[Help] OnChange Field Value change script

Jordan14
Giga Expert

Hello,

I've been tasked with another request to create an OnChange script which once something is inputted into a different field it triggers

the OnChange script and changes the value in a different field.

For example,

State: 1

name : <nothing>

after changes:

State: 2

name: Jordan Thompson

From this, you can see a name was imputted and the state changed from "1" to "2".

Thanks,

Jordan

1 ACCEPTED SOLUTION

Hi Jordan,



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


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


return;


}



//Type appropriate comment here, and begin script below


var check= g_form.getValue('state');


var ad=g_form.getValue('assigned_to');


if(check=='2' && ad != '')     //assumed "root couse required" value is 2. you can check this value at your end from choice .


{


g_form.setValue('state','<your state value that you want to set>');


}



}



Let me know if it does not help


View solution in original post

8 REPLIES 8

kristian dimitr
Tera Guru

Hi Jordan



Make your client script onChange for state and with g_form.setValue(name, Jordan) sets the value for the required field.



Rgards!


Kristian


Hello Kristian,



Thanks for the reply, but could you post the entire cilent script as an example.



That would be really helpful.




Kind Regards,


Jordan


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


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


return;


}



//Type appropriate comment here, and begin script below


var check= g_form.getValue('state');


if(check=='2')


{


g_form.setValue('name','harshvardhan'); //assuming name is a field


}



}


Harsh Vardhan
Giga Patron

if possible can you share the form screenshot? so it will be easy to guide you .



Client Script Examples — ServiceNow Elite


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