Skip to main content
Inspiring
October 18, 2023
Answered

Field Duplication from a spawned page to another page(s) -- both primary and spawned

  • October 18, 2023
  • 1 reply
  • 2576 views

So, I have a document that spawns two different template pages and am trying to have a field on the spawned page autopopulate a read-only field on one of the primary pages.  I have attempted multiple variations garnered from the forums here with no success and a view from those who actually understand what they're doing would be greatly appreciated.

I am working under the assumption the script will have to run from the field on the spawned page and have placed the script (shared below) in the custom calculation script, custom validation, and javascript with no success.  

//SNIPPET
var cPreFix = "";
var aFieldName = event.target.name.split(".");
if(aFieldName.length > 2)
{
cPreFix = aFieldName[0] + "." + aFieldName[1] + ".";
}
var sourceField = this.getField(cPreFix+"SR.Casualty.Description");
var targetField = this.getField("DISPLAY.Description");
if (sourceField && targetField) {
if (sourceField.valueAsString !== "") {
targetField.value = sourceField.value;
} else {
targetField.value = "";
}
}

This topic has been closed for replies.
Correct answer Nesa Nurani

Nesa, thank you for your assistance. 🙂

If the source field located on the template is empty, the target field should remain empty as well -- that's what I was hoping to accomplish anyway. The target field should only display anything if the user has entered data into the spawned page's source field. 

 

Just ran the console and am unsure where the syntax error is, as the script comes up syntactically correct..  Here are the results... 

var cPreFix = "";
var aFieldName = event.target.name.split(".");
if(aFieldName.length > 2)
{
cPreFix = aFieldName[0] + "." + aFieldName[1] + ".";
}
var sourceField = this.getField(cPreFix+"SR.Casualty.Description");
var targetField = this.getField("DISPLAY.Description");
if (sourceField && targetField) {
if (sourceField.valueAsString !== "") {
targetField.value = sourceField.value;
} else {
targetField.value = "";
}
}
SyntaxError: syntax error
1:Console:Exec
undefined


If you enter value in 'sourcefield' after you spawn page instead of whole first part of the script you can just use event.value and use script as validation of that field.

Like I wrote you before problem is this part: if (sourceField && targetField) {

For that part to work both fields should have value which will not be true since you want to populate target field with source field value (so logically target field will be empty) and that part will never trigger so remove it and test script then.

Try something like this as Validation script of 'sourcefield':

var targetField = this.getField("DISPLAY.Description");
if(event.value !== "") {
targetField.value = event.value;
} else {
targetField.value = "";
}

1 reply

Nesa Nurani
Community Expert
October 18, 2023

Spawning template doesn't trigger scripts.

Instead, set a script to autopopulate the field to run after the script you used to spawn template.

Inspiring
October 18, 2023

Nesa, thank you for your response! 🙂 

I have attempted to place the script in the source field of the spawned page (I have trieed all; java, validation, & calculation areas) with the thought that after the page is spawned, the user enters data and the data is replicated in a read only field on the main page.  For whatever reason, after the template is spawned and data is entered into the source field on the spawned page, I cannot get it to replicate on the primary page (or any other page for that matter).

Nesa Nurani
Community Expert
October 18, 2023

Nesa, thank you very much. Your advice absolutely did the trick for the source field to target field display and that is working like a champ.  🙂

I don't suppose you might know why the use of the your solution combined with show/hide of other fields within the same script would prevent show/hide on the spawned pages?    I've been working this one since implementing your earlier solution and for whatever reason, cannot get show/hide to operate on the spawned pages -- although it works on the visible template.... your solution works on both thankfully. 🙂

Here is the script mashed with your earlier solution and again my sincerest thanks for your expertise. 
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)) {
this.getField("DISPLAY.USCG.Finding").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;
}

 


Check console for errors.