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

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

Participant ,
Feb 19, 2024 Feb 19, 2024

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
2.5K
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 ,
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.

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

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

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

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

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

Hi Try67,

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

Kind regards,

 

Steve

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

It should. Share the file for further help.

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

Hi Try67,

 

Thanks for your help with this. Test form attached

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 ,
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.

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

Brilliant, Many thanks for all your help.

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

Check if field is not null:

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

//rest of your script

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

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

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

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

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

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

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

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

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

Thanks Nesa,

 

But Try67 is correct, it's not working.

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

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.

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

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

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