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

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

Contributor ,
Oct 18, 2023 Oct 18, 2023

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

TOPICS
JavaScript , PDF , PDF forms
2.0K
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
Community Expert ,
Oct 18, 2023 Oct 18, 2023

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

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
Community Expert ,
Oct 18, 2023 Oct 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.

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
Contributor ,
Oct 18, 2023 Oct 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).

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
Community Expert ,
Oct 18, 2023 Oct 18, 2023

Check console for errors, also this part: if (sourceField && targetField) {

 will not trigger if both fields are empty.

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
Contributor ,
Oct 18, 2023 Oct 18, 2023

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

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
Community Expert ,
Oct 18, 2023 Oct 18, 2023

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 = "";
}
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
Contributor ,
Oct 18, 2023 Oct 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;
}

 

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
Community Expert ,
Oct 18, 2023 Oct 18, 2023

Check console for errors.

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
Contributor ,
Oct 18, 2023 Oct 18, 2023

It's presenting "undefined" which I have been informed shows there are no foreseeable errors but I'm not entirely certain. :S

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
Community Expert ,
Oct 18, 2023 Oct 18, 2023

Edit.

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
Community Expert ,
Oct 18, 2023 Oct 18, 2023

If you use the script in the same place as the one before, it won't work.

You need to use this script in checkbox field as Mouse UP action.

 

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
Contributor ,
Oct 18, 2023 Oct 18, 2023

I am only able to use it in the Actions tab, MouseUp->Run a JavaScript on the checkbox field. I am just not understanding why it will not work on the spawned pages. :S

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
Community Expert ,
Oct 18, 2023 Oct 18, 2023
LATEST

If It's still not working for you, share your file, so we can see what is going on.

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