The CreatorCon Call for Content is officially open! Get started here.

Calculating multiple Choice field values

ServNowDev
Tera Guru

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.

1 ACCEPTED SOLUTION

@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.

 

sainathnekkanti_0-1703605994537.png

 

For one of the Incident record, I have updated the choice values as per the below. 

 

sainathnekkanti_1-1703606073344.png

 

Executed the same script from BG and I got the desired output. Please refer below screenshot.

 

sainathnekkanti_2-1703606135011.png

 

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.

View solution in original post

6 REPLIES 6

ServNowDev
Tera Guru

I am still getting an error that i cannot convert  Null to an object

@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.

 

sainathnekkanti_0-1703605994537.png

 

For one of the Incident record, I have updated the choice values as per the below. 

 

sainathnekkanti_1-1703606073344.png

 

Executed the same script from BG and I got the desired output. Please refer below screenshot.

 

sainathnekkanti_2-1703606135011.png

 

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.