- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-22-2023 12:50 PM
I have 5 choice fields on a form,
choice field 1 = label of Yes and a value of 3
label of NO and Value of 0
choice field 2 = label of Yes and a value of 3
label of NO and Value of 0
choice field 3 = label of Yes and a value of 3
label of NO and Value of 0
choice field 4 = label of Yes and a value of 3
label of NO and Value of 0
I also have a field Integer that will hold the total
I want to capture the yes and no of each choice and add the sum to the total field. Here is my business rule i am using , after update
var fieldstoTotal = ['current.choice_field1', 'current.choice_field2', 'current.choice_field3', 'current.choice_field4'];
var total = 0;
fieldstoTotal.forEach(function(fieldName) {
var fieldValue = parseFloat(current.getValue(fieldName)) || 0;
total += fieldValue;
});
current.setValue('survey_score', total);
for some reason im not sure why its coming back undefined for the fields.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-26-2023 07:56 AM
@ServNowDev : To replicate the scenario, I created two choice fields, similar to your use case, and I executed the script that I posted earlier, which is working. Please refer to the below screenshots.
For one of the Incident record, I have updated the choice values as per the below.
Executed the same script from BG and I got the desired output. Please refer below screenshot.
Please make sure that your code is correct as per the sample I provided and test it out.
Please mark this as correct answer and helpful if it resolved, or mark this helpful if this help you to reach towards solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-26-2023 12:47 AM
I am still getting an error that i cannot convert Null to an object
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-26-2023 07:56 AM
@ServNowDev : To replicate the scenario, I created two choice fields, similar to your use case, and I executed the script that I posted earlier, which is working. Please refer to the below screenshots.
For one of the Incident record, I have updated the choice values as per the below.
Executed the same script from BG and I got the desired output. Please refer below screenshot.
Please make sure that your code is correct as per the sample I provided and test it out.
Please mark this as correct answer and helpful if it resolved, or mark this helpful if this help you to reach towards solution.