Auto populate value based on variable select variables
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-07-2024 09:20 PM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-07-2024 10:24 PM
Hi @Krishna Priya ,
use below script where i have removed that newValue =='' condition from first if condition
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading){
return;
}
if ((newValue == 'usb')||(newValue=='windows')) {
g_form.setValue('receiver', 'text');
} else {
g_form.setValue('receiver', 'call');
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-07-2024 10:53 PM - edited 02-07-2024 10:55 PM
Hi @Krishna Priya ,
based on your comment, here I have assumed the initial choice of Sender is USB. When you open the form, the sender default choice will be "USB" and based on it Receiver field will be auto-populated as Text.
If user change the Sender as Laptop or Mail, receiver will auto-set as Call
If Sender is Empty/none then receiver will also set as empty/none.
Follow below steps to achieve the functionality:
1. Set the default value for Sender as per your requirement.
2. Write the Onchange Client script for variable "Sender"
Script:
Please hit the like button if my suggestion has helped you in any way.
Please mark correct if my response has solved your query.
Thanks & Regards
Jyoti Jadhav

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-07-2024 10:03 PM - edited 02-07-2024 10:04 PM
Hi @Krishna Priya use below script:
function onChange(control, oldValue, newValue, isLoading) {
if newValue == '') {
g_form.setValue('variablename',''); // clear the value when variable is empty
}
var getSender = g_form.getValue('variablename');
if(getSender=='usb' || getSender=='windows'){
g_form.setValue('variablename','choiceValue');
}
}
Harish