Skip to main content
Participating Frequently
April 18, 2016
Answered

Script code adjustment request

  • April 18, 2016
  • 1 reply
  • 779 views

I would like some help with adjusting this script in our custom calculation field:

// Get the field values, as numbers

var Goals = +getField("Goals").value;

var GA1 = +getField("GA1").value;

var GB1 = +getField("GB1").value;

var GC1 = +getField("GC1").value;

var GD1 = +getField("GD1").value;

// Set this field value

switch (Goals) {

case 1:

    event.value = GA1;

    break;

case 2:

    event.value = (GA1 + GB1) / 2;

    break;

case 3:

    event.value = (GA1 + GB1 + GC1) / 3;

    break;

case 4:

    event.value = (GA1 + GB1 + GC1 + GD1) / 4;

    break;

default:

    event.value = "";

    break;

}

It was written when our form's "Goals" had the numbers 1 through 4 as options.  Now we have 0 through 4 as options - so shouldn't there be a "case 0" added to this? 

Thank you for any help you can give.

This topic has been closed for replies.
Correct answer try67

Zero. 

This may be an obvious fix, but I don't want to mess it up.  Thanks again!


Change these two lines:

switch (Goals) {

case 1:

To:

switch (Goals) {

case 0:

    event.value = 0;

    break;

case 1:

1 reply

try67
Community Expert
Community Expert
April 18, 2016

Yes, there should be...

Coleen77Author
Participating Frequently
April 18, 2016

Could you tell me exactly how to add it?  I don't know how to write code.

Thanks again!

try67
Community Expert
Community Expert
April 18, 2016

What should the value of the field be in that situation?