- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-19-2024 04:42 AM
In the form I have 10 choice fields with choices 'Green' 'Yellow' 'Red'.
There is a new field called Overall Status which should auto populate based on above 10 fields choice values.
When only there is 2 or less Yellow with No Red - Populate as Minor
When there is 3 or more Yellow or 1 or more Red - Populate as Major
Minor and Major are choice values of Overall Status fields.
I have gone through on Load client script but struck in the middle.
Any help is truly appreciated.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-19-2024 07:11 AM
Here's one way to do that - substituting your field names and choice values
function onLoad() {
var redcnt = 0;
var yellowcnt = 0;
var field1 = g_form.getValue('field_1_name');
var field2 = g_form.getValue('field_2_name');
var field3 = g_form.getValue('field_3_name');
//...same for all 10 fields
var fieldArr = [field1, field2, field3]; //include all 10 variable names
for (var i=0; i<fieldArr.length; i++) {
if (fieldArr[i] == 'red') {
redcnt++;
} else if (fieldArr[i] == 'yellow') {
yellowcnt++;
}
}
if (redcnt > 0 || yellowcnt > 2){
g_form.setValue('overall_status_field_name', 'major');
} else if (redcnt == 0 && yellowcnt < 3) {
g_form.setValue('overall_status_field_name', 'minor');
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-19-2024 05:25 AM
Post your script attempt, and we'll get it sorted. Do you really want this to happen on form/record load, or behind the scenes when one of the 10 choice field values changes?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-19-2024 06:33 AM
Hi Brad,
That 10 fields will also auto populate, there is another scenario for that. So on load client script is preferred.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-19-2024 07:11 AM
Here's one way to do that - substituting your field names and choice values
function onLoad() {
var redcnt = 0;
var yellowcnt = 0;
var field1 = g_form.getValue('field_1_name');
var field2 = g_form.getValue('field_2_name');
var field3 = g_form.getValue('field_3_name');
//...same for all 10 fields
var fieldArr = [field1, field2, field3]; //include all 10 variable names
for (var i=0; i<fieldArr.length; i++) {
if (fieldArr[i] == 'red') {
redcnt++;
} else if (fieldArr[i] == 'yellow') {
yellowcnt++;
}
}
if (redcnt > 0 || yellowcnt > 2){
g_form.setValue('overall_status_field_name', 'major');
} else if (redcnt == 0 && yellowcnt < 3) {
g_form.setValue('overall_status_field_name', 'minor');
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-19-2024 07:43 AM
Awesome, Thank you very much Sir.