
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-02-2023 11:22 AM
I have a requirement where based on 2 variables in the same catalog item, it would set a value into a 3rd variable. This needs to be able to update as the values on the 1st 2 variables change. The 3rd variable has 2 values that can be set into it.
What would be the best way to make this happen?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-02-2023 11:34 AM - edited 06-02-2023 11:36 AM
2 onChange Client Scripts for the first 2 variables. Use the same script for each. Script should look something like the below. Just add more if statements as needed. With 2 onChange scripts, this script would run when either of the first 2 variables changed, but only set field 3 when both field 1 and 2 were whatever you wanted them to be.
function onChange(control, oldValue, newValue, isLoading) {
//Get the first 2 variable values
var field1Val = g_form.getValue('field1');
var field2Val = g_form.getValue('field2');
//Set variable 3 to whatever you need it to be based on the first 2 variables
if (field1Val == 'Whatever Value' && field2Val == 'Whatever Value'){
g_form.setValue('field3','First Value');
}
if (field1Val == 'Whatever Next Value' && field2Val == 'Whatever Next Value'){
g_form.setValue('field3','Second Value');
}
}
Please mark this response as correct and/or helpful if it assisted you with your question.
Steven
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-02-2023 11:34 AM - edited 06-02-2023 11:36 AM
2 onChange Client Scripts for the first 2 variables. Use the same script for each. Script should look something like the below. Just add more if statements as needed. With 2 onChange scripts, this script would run when either of the first 2 variables changed, but only set field 3 when both field 1 and 2 were whatever you wanted them to be.
function onChange(control, oldValue, newValue, isLoading) {
//Get the first 2 variable values
var field1Val = g_form.getValue('field1');
var field2Val = g_form.getValue('field2');
//Set variable 3 to whatever you need it to be based on the first 2 variables
if (field1Val == 'Whatever Value' && field2Val == 'Whatever Value'){
g_form.setValue('field3','First Value');
}
if (field1Val == 'Whatever Next Value' && field2Val == 'Whatever Next Value'){
g_form.setValue('field3','Second Value');
}
}
Please mark this response as correct and/or helpful if it assisted you with your question.
Steven
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-02-2023 11:35 AM