Help with simple onChange script to populate one field, based on another

Zhivko
Kilo Expert

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');

 

 

 

1 ACCEPTED SOLUTION

simonbergstedt
Tera Guru

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

View solution in original post

15 REPLIES 15

Looks like 'Telephony Systems' is what you're looking for.  You just need to test against the correct value for category.  This should work for Telephony Systems.  Add and adjust for the rest.

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
    if (isLoading || newValue == '') {
        return;
    }

    if (g_form.getValue('category') == 'Telephony Systems')
        g_form.setValue('u_responsible', 'Jack');
}

simonbergstedt
Tera Guru

Yes you don't have anything for Telephony Systems, the values the script is looking for is Systems or Network. So if you change "Systems" to "Telephony Systems" you should  Jack as the responsible person

Zhivko
Kilo Expert

ok, got it.

I was not refreshing the browser page, but just the form when testing, so it was not picking up my changes.

(and I did adjust the values in the script to account for the Telephony Systems value - I am not that much of a noob :D)

We don't know your knowledge. Sorry.

And how was that answer correct? Because it helped you troubleshoot the problem? What was the overall change you made?


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

About the knowledge - yes you are right, you could not know.

It was the correct answer, as it is the script that ended up working and it did help me troubleshoot too. 
The change was that I double checked the values/labels for both fields and corrected the script - I populated one of them, so those were fine, but the categories were all over the place, so most were not getting picked up.