Skip to main content
cherriet63150999
Participant
May 22, 2018
Answered

Don't have Javascript experience and after looking through numerous online articles I need help on the proper syntax for the following

  • May 22, 2018
  • 1 reply
  • 480 views

I am using XI Pro.  I have two fields that are named "purchase" and  "undefined".   What I would like to accomplish is If the purchase is > than 1,000 then undefined should be the purchase  times 2 divided by 1,000 but if the purchase is < 1,000 then undefined should only be 2.   Any help would be appreciated.

Regards,

Cherrie

This topic has been closed for replies.
Correct answer Karl Heinz Kremer

"undefined" is probably not a good field name - I would use something that is more descriptive. For for now, let's go with "undefined". You will need to create a calculation script for the "undefined" field. This script needs to get the value from your "purchase" field and compare it, and then set the field value accordingly. This should work:

var f = this.getField("purchase");

if (f != null) {

  var v = f.value;

  if (v > 1000) {

      event.value = v/2 * 1000;

  }

  else {

      event.value = 2;

  }

}

1 reply

Karl Heinz  Kremer
Community Expert
Karl Heinz KremerCommunity ExpertCorrect answer
Community Expert
May 22, 2018

"undefined" is probably not a good field name - I would use something that is more descriptive. For for now, let's go with "undefined". You will need to create a calculation script for the "undefined" field. This script needs to get the value from your "purchase" field and compare it, and then set the field value accordingly. This should work:

var f = this.getField("purchase");

if (f != null) {

  var v = f.value;

  if (v > 1000) {

      event.value = v/2 * 1000;

  }

  else {

      event.value = 2;

  }

}

cherriet63150999
Participant
May 22, 2018

Hello Karl,

Thank you for the quick response.   I entered the formula and am receiving the following error, any suggestions.   Also I hope that I modified the one event.value correctly since I need the purchase if > 1,000 to be *2/1000.

Regards,

Cherrie

Legend
May 22, 2018

There is a spelling mistake on your first line.