Auto populate value based on variable select variables

Krishna Priya
Tera Contributor

Auto populate value based on variable

I have two variables called sender and receiver.

In sender, choices are mail, usb, windows, land, laptop

Receiver choices are text and call.

 

If i choose sender either usb or windows, i want to populate the Receiver has text.

 

Please help me with script in catalog client script.  

12 REPLIES 12

Hi @Krishna Priya 

 

Use this -

function onChange(control, oldValue, newValue, isLoading) {
   if (newValue == '') {
var sender = g_form.getValue('backend_name_of_sender_field');
if(sender=='usb' || sender=='windows'){
g_form.setValue('backend_name_of_reciever_field','text');
}
else{
g_form.setValue('backend_name_of_reciever_field','call');
}
      return;
   }

var sender = g_form.getValue('backend_name_of_sender_field');
if(sender){
if(sender=='usb' || sender=='windows'){
g_form.setValue('backend_name_of_reciever_field','text');
}
else{
g_form.setValue('backend_name_of_reciever_field','call');
}
}
}

 

Mark Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.

Sarika S Nair1
Kilo Sage

Hi, 

Create one onchange catalog client script on sender field 

 

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

if ((newValue == 'usb')||(newValue=='windows')) {
g_form.setValue('receiver', 'text');
} else {
g_form.setValue('receiver', 'call');
}
}

Sayali Gurav
Tera Guru
Tera Guru

Hello @Krishna Priya ,

You can use onChange client script :

SayaliGurav_0-1707371038347.png

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
   if (isLoading || newValue === '') {
      return;
   }
   var sender = g_form.getValue('u_sender');
if(sender=='usb' ||sender =='windows' )
{
    g_form.setValue('u_receiver','text');
}
else{
    g_form.setValue('u_receiver','call');
}  
}
 
 
Please mark helpful and accept as solution if this will helps you.
 
Thanks and Regards,
Sayali Gurav

I have tested it. But only its working on on change, if i choose initially, the value is not getting populated. But if i change its working.

I want to populate the value if they select initially also.

In else case if want to include none , which is default option. Please suggest on that

Hi @Krishna Priya ,

 

Are you setting any default choice value for "Sender" variable?

 

Regards

Jyoti Jadhav