- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-07-2018 09:16 AM
Hi, I am trying to setup a dependency between 2 string fields on one of our forms (change_request table if that matters)
I tried a few things based on what i found here in the community, but unsuccessfully.
This is the most basic thing I could come up with and even that did not work.
I am setting the field name that this is supposed to apply to to Category.
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue == '') {
return;
}
if (g_form.getValue('category') == 'Systems')
g_form.setValue('u_responsible', 'Jack');
if (g_form.getValue('category') == 'Networks')
g_form.setValue('u_responsible', 'Sam');
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-07-2018 10:03 AM
Do you get the values you want if you just print them out in a g_form.addInfoMessage like
var cat = g_form.getValue('category');
var responsible = "";
if(cat == 'Systems';
{
responsible = "Jack";
}
else if(cat == 'Networks')
{
responsible = "Sam";
}
g_form.addInfoMessage("Category is " + cat + " so the responsible person is " + responsible;
I find that it always helps out when troubleshooting things like this

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-07-2018 09:20 AM
Is 'u_responsible' a reference field? If so, you'll want to use 'setDisplayValue' to set the friendly name instead of the sys_id.
g_form.setDisplayValue('u_responsible', 'Sam');

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-07-2018 09:25 AM
need to use getDisplayValue unless the value in the back-end is specifically saying 'Systems'. It is case sensitive.
And then your set value to the exact value (not display value).
You don't have brackets either...and so you could do it like this:
if (newValue == 'Systems'){
g_form.setValue('u_responsible', 'Jack');
}
You've already chosen the field on the client script, so now you can tap in to newValue
Need to look in to DisplayValue script
Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-07-2018 09:48 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-07-2018 09:55 AM
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === ' ')
return;
if (g_form.getValue('category') == 'Systems')
g_form.setValue('u_responsible', 'Jack');
if (g_form.getValue('category') == 'Networks')
g_form.setValue('u_responsible', 'Sam');
}
Regards,
Sachin