Skip to main content
December 12, 2016
Question

How do I populate field 1 with the amount from field 2 based on the description of field 3?

  • December 12, 2016
  • 2 replies
  • 405 views

How do I populate field 1 with the amount from field 2 based on the description of field 3? I am new to java script and so far I have placed in the calculate tab   
if (description == “Single Life”) this.getField(amount);
Needless to say this does not work.
Any help is appreciated.

This topic has been closed for replies.

2 replies

Inspiring
December 12, 2016

For that to work, the custom calculation script for field 1 would have to be something like:

// Get the field values

var sDesc = getField("description").valueAsString;  // string

var nAmount = getField("amount").value;  // number

// Set this field value

if (sDesc === "Single Life") {

    event.value = nAmount;

} else {

    event.value = "";  // Blank this field

}

You can add "else if" blocks to handle other cases, or use the "switch" JavaScript statement instead, which is what I'd recommend.

try67
Community Expert
Community Expert
December 12, 2016

As the custom calculation script of field 1 you can use this code, for example:

if (this.getField("description").valueAsString=="Single Life") event.value = this.getField("amount").value;

else event.value = "";

December 12, 2016

thank you very much - worked like a charm!!