- 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:32 AM - edited 08-19-2024 05:33 AM
Hey @Avinash72 ,
Can you try to create a custom data lookup table. So, this functionality would be similar to the priority field auto population in incident form based on impact and urgency fields.
dl_u_priority is the lookup table for priority field, go through it and see if it makes sense to use a similar approach for your use case.
If you opt for a custom data lookup here is the docs link Custom data lookup (servicenow.com)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-19-2024 07:45 AM
Thank you for your reply.