HRSD Form with onChange client script to clear out a field based on two other fields being null

Scott Megargee
Tera Expert

I have a HRSD form with three fields first_name, last_name, user_name. I have an onChange client script on the first_name and last_name variables that will set the user_name field and this is working as expected. My issue is if a user deletes the data in the first_name and last_name fields the user_name field retains the original data. I need this cleared out. I attempted the below script but it's not working.

 

function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
if (g_form.getValue('first_name' == "") && g_form.getValue('last_name' == ""))
g_form.setValue('user_name', ' ');
}

 

Any thoughts on where I'm going wrong here?

1 ACCEPTED SOLUTION

Amit Gujarathi
Giga Sage
Giga Sage

HI @Scott Megargee ,
I trust you are doing great.

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading) {
        return;
    }
    if (g_form.getValue('first_name') == "" && g_form.getValue('last_name') == "") {
        g_form.setValue('user_name', '');
    }
}

Was this answer helpful?


Please consider marking it correct or helpful.


Your feedback helps us improve!


Thank you!


Regards,


Amit Gujrathi



View solution in original post

2 REPLIES 2

Amit Gujarathi
Giga Sage
Giga Sage

HI @Scott Megargee ,
I trust you are doing great.

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading) {
        return;
    }
    if (g_form.getValue('first_name') == "" && g_form.getValue('last_name') == "") {
        g_form.setValue('user_name', '');
    }
}

Was this answer helpful?


Please consider marking it correct or helpful.


Your feedback helps us improve!


Thank you!


Regards,


Amit Gujrathi



Thanks Amit. Appreciate the quick response worked great.