Copy link to clipboard
Copied
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---
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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?
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
I've continued tinkering with the previously shared script on both the actual template and spawned template pages simultaneously.
The template page works irrespective of script order, e.g. moving "targetField.value = "USCG";" anywhere
below "this.getField(cPreFix+"Text.CG-835.Finding").display = display.visible;" etc. -- before the "} else {" statement of course. 😉
The spawned page will not execute any of the lines when "targetField.value = "USCG";" is moved anywhere below the "this.getField(cPreFix+"Text.CG-835.Finding").display = display.visible;" line. While "targetField.value = "USCG";" works as required only when residing at the top immediately following the "if (event.target.isBoxChecked(0))" statement. If I understand correctly, provided the sequencing is properly ordered those elements calling for a specific execution following an "if" statement can be in any order?
I may be totally off here but is the cPreFix method being utilized somehow not able to account for the incredibly long spawned template prefix? The field name of one of the problem checkboxes on the actual template page is "SR.Casualty.Description" which becomes "P3.IRR.DRRS.EQUIP.TEMP.SR.Casualty.Description" once spawned.
While I am probably totally off as I clearly do not understand how the elements of the cPreFix method work, the "if(aFieldName.length > 2)" line has me wondering -- again with no real understanding at all -- if this is somehow creating a limitation on recognizing the spawned fields based on the new length of the fieldname.
Any thoughts or advice and my sincerest thanks for your time.
Very Respectfully,
Charlie
var cPreFix = "";
var aFieldName = event.target.name.split(".");
if(aFieldName.length > 2)
{
cPreFix = aFieldName[0] + "." + aFieldName[1] + ".";
}
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
Thom,
Thank you for your explanation. This has been driving me bananas for two days and I had no idea -- with zero understanding -- what was wrong. I truly appreciate the assist.
Very Respectfully,
Charlie