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



Is this on a catalog item and are they having same names? Because you should not get this issue if they are difference variable names.


Hi Venkat,



This field are on a change form and one is assigned to and the other one is validator and they are both using sys_user table.


Eliana,



You can get this done by using "On Change" or "On Submit" client scripts. What is the field values of the two fields ? I will give you a sample script which you can use.



~Raghu.


Raghu Loganatha
Kilo Guru

Eliana,



You can add a " On change " client script on the second field.



Read the value from both the reference fields and add a if condition.



if(first value == second value)


{


//script


if you want alert or clear the value


}



~Raghu.