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

Script stopped working: this.getAnnot(...) is null

Community Beginner ,
May 03, 2021 May 03, 2021

Copy link to clipboard

Copied

I just finished testing a section of my form and now all of a sudden the script isn't working and I'm getting console errors????

 

This section has a serious of checkboxes which either instruct the user to Continue to the next section or Stop. The sections are semi-hidden by a 50% transparent gray rectangle annotation until the user checks the Continue box. If the continue box is unchecked the gray rectangle reappears. The checkboxes also turn certain fields on and off underneath the gray rectangle. I used the following code and it worked great about two hours ago:

 

 

if(event.target.isBoxChecked(0))
{
showHide("B1.txt.SFM.Receive.Go");
EnableField("B1.SFM.Location");
this.getAnnot(0,"B1.2.Rect").hidden = true;
}
if(event.target.value=="Off")
{
showHide("B1.txt.SFM.Receive.Go");
DisableField("B1.SFM.Location");
this.getAnnot(0,"B1.2.Rect").hidden = false;
}

 

showHide, EnableField and DisableField are document level functions which toggle fields on and off. That part is still working fine.

 

But the rectangles don't change and I just get an error in the console now: this.getAnnot(...) is null

 

??

TOPICS
JavaScript , PDF forms

Views

1.2K

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 , May 03, 2021 May 03, 2021

Check if annot name is right.

Do you have multiple pages? because if annot is not on first page you need to change '0' to '1' if it's on second page or '2' if it's on third page ...etc this.getAnnot(0,"B1.2.Rect").hidden = true;

 

Votes

Translate

Translate
Community Expert ,
May 03, 2021 May 03, 2021

Copy link to clipboard

Copied

Is it an annotation or a 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 Beginner ,
May 03, 2021 May 03, 2021

Copy link to clipboard

Copied

An annotation.  A gray rectangle

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 ,
May 04, 2021 May 04, 2021

Copy link to clipboard

Copied

Try adding this line before using getAnnot:

this.syncAnnotScan();

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 ,
May 03, 2021 May 03, 2021

Copy link to clipboard

Copied

Check if annot name is right.

Do you have multiple pages? because if annot is not on first page you need to change '0' to '1' if it's on second page or '2' if it's on third page ...etc this.getAnnot(0,"B1.2.Rect").hidden = true;

 

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 ,
May 03, 2021 May 03, 2021

Copy link to clipboard

Copied

How did you set the annotation name?

 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

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 Beginner ,
May 05, 2021 May 05, 2021

Copy link to clipboard

Copied

LATEST

I set the name in the console using:

this.selectedAnnots[0].name = "B1.2.Rect";

 

I think the immediate problem was the page numbers, although I'm confused about why it worked for a while and then stopped working.

 

I am still wondering if I need to also address any of the following:

1) Maybe I need to change the name so it doesn't end with .rect

2) Should I also add:

this.syncAnnotScan();

before getAnnot

3) Should I set a document level variable first:

var annot = this.getAnnot(pg#,"AnnotationName");

and then use annot.hidden = true in my calculation 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