How to make 2 reference field on a form not to accept the same value?

eliana_wise
Tera Contributor

Hi,

I have two reference fields that are for users, and I would like for the second reference field not to accept the same value that has been chosen in the   first reference field.

Thanks

1 ACCEPTED SOLUTION

Shishir Srivast
Mega Sage

Please have this onChange() client script on second reference field.



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


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


          return;


    }


    //Type appropriate comment here, and begin script below


        var first_user = g_form.getValue('first reference field name'); //Update the field name here


        if(first_user == newValue)


        {


                  alert('User can not be the same');


                  g_form.clearValue('second reference field'); //Update the field name here


        }    


}


View solution in original post

7 REPLIES 7

venkatiyer1
Giga Guru

Hi Eliana,



i have two fields on my change form in the same fashion as what you have mentioned and i am not getting the issue. Do you have any attributes on both the columns or any script that might be autopopulating? Out of the box you should not be having this issue.


Shishir Srivast
Mega Sage

Please have this onChange() client script on second reference field.



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


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


          return;


    }


    //Type appropriate comment here, and begin script below


        var first_user = g_form.getValue('first reference field name'); //Update the field name here


        if(first_user == newValue)


        {


                  alert('User can not be the same');


                  g_form.clearValue('second reference field'); //Update the field name here


        }    


}


Thanks so much Shishir