Skip to main content
JMFreeman
Inspiring
May 17, 2021
Answered

Set Custom Calculation Script through console?

  • May 17, 2021
  • 1 reply
  • 556 views

Is it possible to use a loop in the debugger console to set the custom calculation of multiple fields to a script? I believe I have the right idea here, but I need help making my loop. I want to work through every field with "Quant" in its name (I have Quant A1, Quant A2, Quant B1, etc.). They will all have the same calculation script.

for (var i = 0; i < this.numFields; i++){
	if(/*need logic here to match "Quant" in the field name*/){
		this.getField(/*field*/).setAction("Calculate", /*my custom calculation script will be here */);
	}
}

 I'm just unsure what the logic is to check the beginning of each field name for "Quant". Thank you, community!

This topic has been closed for replies.
Correct answer JMFreeman

I figured out what I was looking for. It was the string.match() function, usuing regular expressions. This instance ignores case and should (hopefully) be grabbing any field whose name contains "quant".

for (var i = 0; i < this.numFields; i++){
	var f = this.getField(getNthFieldName(i));
	if(f.name.match(/quant/i) != null){
		f.setAction("Calculate", "test");
	}
}

1 reply

JMFreeman
JMFreemanAuthorCorrect answer
Inspiring
May 18, 2021

I figured out what I was looking for. It was the string.match() function, usuing regular expressions. This instance ignores case and should (hopefully) be grabbing any field whose name contains "quant".

for (var i = 0; i < this.numFields; i++){
	var f = this.getField(getNthFieldName(i));
	if(f.name.match(/quant/i) != null){
		f.setAction("Calculate", "test");
	}
}