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

Set Custom Calculation Script through console?

Participant ,
May 17, 2021 May 17, 2021

Copy link to clipboard

Copied

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

Views

319

Translate

Translate

Report

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

correct answers 1 Correct answer

Participant , May 18, 2021 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");
	}
}

Votes

Translate

Translate
Participant ,
May 18, 2021 May 18, 2021

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

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