
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-02-2017 05:49 AM
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
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-03-2017 04:47 AM
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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-02-2017 06:51 AM
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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-02-2017 07:08 AM
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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-02-2017 07:11 AM
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
}
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-02-2017 07:13 AM
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