Skip to main content
Inspiring
October 19, 2023
Answered

Spawned page scripting only partially working...

  • October 19, 2023
  • 1 reply
  • 1388 views

After combing through the forums and garnering some valuable pointers and advice from Nesa, scripting on a spawned template page is now working where it auto-populates other read-only fields.  Unfortunately, it refuses to work when combined with show/hide fields. 

The script, sans show/hide is identical to what I've implemented in all the required fields and works as it should -- it even works for the "targetField.value" in the example below.  It's refusing to show/hide the fields listed on the spawned page while working as needed on the actual template (non-spawned) page. 

The JS Debugger returns the following: SyntaxError: syntax error 1:Console:Exec undefined and irrespective of research, I've been unable to figure out what this specifically means and/or how to implement fixing it.  Hopefully, the subject matter experts here will get a chuckle and be able to show me where I've screwed something up.  


Here is the script and my sincerest thanks in advance for any assistance or advice. 

//---BEGIN Cut & Paste---
var cPreFix = "";
var aFieldName = event.target.name.split(".");
if(aFieldName.length > 2)
{
cPreFix = aFieldName[0] + "." + aFieldName[1] + ".";
}
var sourceField = this.getField(cPreFix+"Finding.USCG");
var targetField = this.getField("DISPLAY.USCG.Finding");
if (event.target.isBoxChecked(0)) {
targetField.value = "USCG";
this.getField(cPreFix+"Text.CG-835.Finding").display = display.visible;
this.getField(cPreFix+"Text.CG-835.Yes").display = display.visible;
this.getField(cPreFix+"Text.CG-835.No").display = display.visible;
this.getField(cPreFix+"CG-835.Finding").display = display.visible;
} else {
targetField.value = "";
this.getField(cPreFix+"Text.CG-835.Finding").display = display.hidden;
this.getField(cPreFix+"Text.CG-835.Yes").display = display.hidden;
this.getField(cPreFix+"Text.CG-835.No").display = display.hidden;
this.getField(cPreFix+"CG-835.Finding").display = display.hidden;
}

//---END Cut & Paste---

This topic has been closed for replies.
Correct answer Thom Parker

You state:

 "SR.Casualty.Description" which becomes "P3.IRR.DRRS.EQUIP.TEMP.SR.Casualty.Description" 

 

Well there's your problem right there:

The real prefix is "P3.IRR.DRRS.EQUIP.TEMP" but it's only getting "P3.IRR"

This contains (dot separated) 5 parts. The code expects the prefix to be 2 parts. So the template name must contain 4 parts. 

This is what I meant by missing context, so thanks for filling in the details. 

 

The solution is to add the extra bits onto "cPrefix" or remove the dots from the template name. The dot separated field names, while great for organizing data, are a problem for code that expects to detect a templated page by counting parts. You might consider a different strategy for template dections and prefix creation. 

 

 

 

1 reply

Thom Parker
Community Expert
Community Expert
October 19, 2023

The error reported in the console indicates a syntax error on line 1, on code run inside the console window. Are you running this code from the console window?  If not then this error is for something else. 

 

There is nothing obviously wrong with the code. But we're missing context.

From where is the code run?  It looks like it's intended for an event on a field on a template where the fields are renamed when spawned.   Is this the case?

 

 

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
Inspiring
October 19, 2023

Thom,

 

     Thank you for replying.  To answer your questions, yes this particular script was run independently within the console window and yes, the script is contained within a template field that is spawned from within the document. 

Very Respectfully,

Charlie