Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Set Custom Calculation Script through console?

Participant ,
May 17, 2021 May 17, 2021

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!

TOPICS
Create PDFs , JavaScript , PDF forms
502
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
1 ACCEPTED SOLUTION
Participant ,
May 18, 2021 May 18, 2021
LATEST

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");
	}
}

View solution in original post

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
May 18, 2021 May 18, 2021
LATEST

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");
	}
}
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines