Skip to main content
Inspiring
February 19, 2024
Answered

How to check that a spawned page exists in a document using a hidden text field.

  • February 19, 2024
  • 2 replies
  • 4326 views

Hi all,

 

I need to figure out a way of checking for a hidden text field on a spawned page and if that field isn't found then spawn that page. 

 

So far i have this:

var f = this.getField("Page text 5.1").page;

var v = this.getField("Section 4").page;

if (f !== true){
this.spawnPageFromTemplate({
cTemplate: "Page5",
nPage: v+2,
bOverlay: false,
bRename: false
});}

 

Any help will be greatly appreciated. 

 

Steve

 

This topic has been closed for replies.
Correct answer try67

Hi Try67,

 

Thanks for your help with this. Test form attached


The name of the field is "Page text 5", not "Page text 5.1". Adjust the code accordingly and it will work.

Same goes for "Page text 6.1", etc.

2 replies

Nesa Nurani
Community Expert
February 19, 2024

Check if field is not null:

var f = this.getField("Page text 5.1");
if(f !== null){

//rest of your script

try67
Community Expert
February 19, 2024

That won't work. If the field exists on a hidden Template page it will not return null.

Nesa Nurani
Community Expert
February 19, 2024

You are right, I thought he wanted the other way around.

try67
Community Expert
February 19, 2024

Before the page is spawned, the page property of that field will return a number (-1). Afterwards it will return an array, with one of the values being-1 and the other being the page number to which you spawned it.

So you can check the type of the object returned by the page property. If it's "number" it means the page hasn't been spawned (if you want to double-check that the template page is hidden you can check it's -1); If it's an "object" (meaning an array), that means there are multiple copies if it, and the page has been spawned.

This is all assuming this field only exists one, and on the Template page only, of course.

Inspiring
February 19, 2024

Thanks for your answer, so how do I search for an object as opposed to a number?

Inspiring
February 20, 2024

The name of the field is "Page text 5", not "Page text 5.1". Adjust the code accordingly and it will work.

Same goes for "Page text 6.1", etc.


Brilliant, Many thanks for all your help.