Skip to main content
Inspiring
Oct 26, 2017 4:45 PM UTC
Answered

Can a field name be changed with an incremented value based on a condition?

I want to replace "X" in

  var chk = this.getField("PX.myCheck.chkAmount")

using an incremented value based on a condition.

My objective is to add script to this example so that if(num2.value > "") then the field name "PX.myCheck.chkAmount" will become "P1.myCheck.chkAmount". 

Example:

var num2 = this.getField("num.chk.02");

var i = 0

if(num2.value > "")(i = i + 1; var chk = this.getField("P1.myCheck.chkAmount";chk.value = num2.value);

This topic is closed to new replies. Start a new post to keep the conversation going.
try67
try67Correct answer
Community Expert
Oct 26, 2017 5:05 PM UTC

Yes: this.getField("P"+i+".myCheck.chkAmount")

3 replies

try67
Community Expert
try67Community ExpertCorrect answer
Community Expert
Oct 26, 2017 5:05 PM UTC

Yes: this.getField("P"+i+".myCheck.chkAmount")

Translate
ODuinnAuthor
Inspiring
Oct 27, 2017 11:57 AM UTC

Thank you. I did not know that you could do that within the field name parenthesis. I thought the open and close quotes would be discarded with the result being this.getField(P1myCheck.chkAmount) rather than this.getField(“P1myCheck.chkAmount”). This is the simplest of solutions.

David

Translate
try67
Community Expert
Community Expert
Oct 27, 2017 12:00 PM UTC

The field-name parameter is just a string. As such, it can be manipulated just like any other string in your code.

Translate