- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-31-2023 10:42 AM
So there are 2 fields in a catalogue item- one is Name and other is code.
Name is select box type. So it has multiple options like Ai, Dm, dj, gu, ji, kl, nv.
So when someone selects ai or DM or DJ then it needs to populate 78 number in Code field.
And if someone selects ji ,gu, kl ,then it needs to popoulate 45 number in Code field.
How to do this using client script
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-31-2023 10:51 AM - edited ‎10-31-2023 10:52 AM
Hi @User_267 ,
You need to write an onChange client script on Name field.
Pls try this code: use proper backend names for name & code field
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
// Get the selected value from the Name field
var nameValue = g_form.getValue('name');
// Set the Code field based on the selected Name value
if (nameValue == 'ai' || nameValue == 'AI' || nameValue == 'DM' || nameValue == 'dj') {
g_form.setValue('code', '78');
} else if (nameValue == 'ji' || nameValue == 'gu' || nameValue == 'kl') {
g_form.setValue('code', '4
5');
}
Thanks,
Danish
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-31-2023 10:56 AM
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
//Type appropriate comment here, and begin script below
if (newValue == 'DM' || newValue == 'DJ') {
g_form.setValue('code', '78');
} else if (newValue == 'ji' || newValue == 'gu' || newValue == 'kl') {
g_form.setValue('code', '45');
}
else if (newValue == 'au' || newValue == 'DG' || newValue == 'hj') {
g_form.setValue('code', '67');
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-31-2023 10:51 AM - edited ‎10-31-2023 10:52 AM
Hi @User_267 ,
You need to write an onChange client script on Name field.
Pls try this code: use proper backend names for name & code field
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
// Get the selected value from the Name field
var nameValue = g_form.getValue('name');
// Set the Code field based on the selected Name value
if (nameValue == 'ai' || nameValue == 'AI' || nameValue == 'DM' || nameValue == 'dj') {
g_form.setValue('code', '78');
} else if (nameValue == 'ji' || nameValue == 'gu' || nameValue == 'kl') {
g_form.setValue('code', '4
5');
}
Thanks,
Danish
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-31-2023 10:52 AM
@User_267 Configure your script as follows.
Here is the script.
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
//Type appropriate comment here, and begin script below
if (newValue == 'DM' || newValue == 'DJ') {
g_form.setValue('code', '78');
} else if (newValue == 'ji' || newValue == 'gu' || newValue == 'kl') {
g_form.setValue('code', '45');
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-31-2023 10:54 AM
For two options it is if and else if condition if there is other options like au,DG,hj then it needs to populate 67.along with the above

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-31-2023 10:56 AM
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
//Type appropriate comment here, and begin script below
if (newValue == 'DM' || newValue == 'DJ') {
g_form.setValue('code', '78');
} else if (newValue == 'ji' || newValue == 'gu' || newValue == 'kl') {
g_form.setValue('code', '45');
}
else if (newValue == 'au' || newValue == 'DG' || newValue == 'hj') {
g_form.setValue('code', '67');
}
}