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

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

Explorer ,
Feb 19, 2024 Feb 19, 2024

Copy link to clipboard

Copied

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

 

TOPICS
JavaScript , Modern Acrobat , PDF

Views

761

Translate

Translate

Report

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

correct answers 1 Correct answer

Community Expert , Feb 20, 2024 Feb 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.

Votes

Translate

Translate
Community Expert ,
Feb 19, 2024 Feb 19, 2024

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

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
Explorer ,
Feb 19, 2024 Feb 19, 2024

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

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 ,
Feb 19, 2024 Feb 19, 2024

Copy link to clipboard

Copied

You can use something like this:

 

if (typeof this.getField("Page text 5.1").page=="number") {
	// The template page HAS NOT been spawned
} else {
	// The template page HAS been spawned
}

Votes

Translate

Translate

Report

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
Explorer ,
Feb 19, 2024 Feb 19, 2024

Copy link to clipboard

Copied

Hi Try67,

Thanks for your help but doesn't seem to work either. 

Kind regards,

 

Steve

Votes

Translate

Translate

Report

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 ,
Feb 19, 2024 Feb 19, 2024

Copy link to clipboard

Copied

It should. Share the file for further help.

Votes

Translate

Translate

Report

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
Explorer ,
Feb 20, 2024 Feb 20, 2024

Copy link to clipboard

Copied

Hi Try67,

 

Thanks for your help with this. Test form attached

Votes

Translate

Translate

Report

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 ,
Feb 20, 2024 Feb 20, 2024

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

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
Explorer ,
Feb 20, 2024 Feb 20, 2024

Copy link to clipboard

Copied

LATEST

Brilliant, Many thanks for all your help.

Votes

Translate

Translate

Report

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 ,
Feb 19, 2024 Feb 19, 2024

Copy link to clipboard

Copied

Check if field is not null:

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

//rest of your script

Votes

Translate

Translate

Report

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 ,
Feb 19, 2024 Feb 19, 2024

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

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 ,
Feb 19, 2024 Feb 19, 2024

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

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
Enthusiast ,
Feb 19, 2024 Feb 19, 2024

Copy link to clipboard

Copied

It would work, but just check for null not !null, if he doesn't have other copies of the same field.

Votes

Translate

Translate

Report

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 ,
Feb 19, 2024 Feb 19, 2024

Copy link to clipboard

Copied

It will not work. The field will never be null.

Votes

Translate

Translate

Report

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
Explorer ,
Feb 19, 2024 Feb 19, 2024

Copy link to clipboard

Copied

Thanks Nesa,

 

But Try67 is correct, it's not working.

Votes

Translate

Translate

Report

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 ,
Feb 19, 2024 Feb 19, 2024

Copy link to clipboard

Copied

You can spawn a template page and then check if field exist on that page, and if it does exist then delete that page otherwise leave the page spawned.

Votes

Translate

Translate

Report

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
Explorer ,
Feb 19, 2024 Feb 19, 2024

Copy link to clipboard

Copied

Hi Nesa,

 

The ideal scenario I would like to get to is to do a reset to all the spawned pages on all 4 button clicks. I have a script that will delete the spawned pages, using the form field name on the template, but that dies when it can't can't find a field name and the rest of the script doesn't work. I was going to to try If Else but that didn't work, I can't seem to find something that says if not present then ignore and move to next line  (type of thing).

 

Many thnaks for your help so far. You've been amazing and have helped me no end

Votes

Translate

Translate

Report

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