Skip to main content
March 31, 2016
Answered

Reading CheckMark State

  • March 31, 2016
  • 1 reply
  • 1102 views

Hi everyone,

I'm trying to get the state of CheckMark in JavaScript. As per JS API reference, code as below should be used and it works fine.

annots = this.getAnnots()

   for ( var i= 0; i< annots.length; i++) {

      states = annots.getStateInModel("Marked");

      if ( states.length > 0 ) {

         for(j = 0; j < states.length; j++)

         {

            var s = states.state;       

            console.println(s );

         }

  

      }  

   }

But as you know, CheckMark is also a part of an annotation( Sticky Note, Highlight, etc.). When I try to read the same state under the related annotation with InReplyTo, I get nothing.

annots = this.getAnnots()

mark = this.getAnnots()

   for ( var i= 0; i< annots.length; i++) {

         for ( var j= 0; j< mark.length; j++) {

                 if(mark.inReplyTo == annots.name){

                 states = mark.getStateInModel("Marked");

                   if ( states.length > 0 ) {

                      for(k = 0; k < states.length; k++)

                          {

                           var s = states.state;

                           console.println(s)

                           }  

                      }

                 } 

            }

   }

I couldn't figure out what is wrong with this code? Any help is appreciated.

Regards

This topic has been closed for replies.
Correct answer try67

My main goal is to export all the comments into an excel file.

If a comment is checked, in the same row of the excel file user will see his comment and see if it is checked.

So I need to get all the annotations and check if it is checked or not. Thats why I need to use second code above


You don't need to do that. The thing is, though, that checking the reply itself seems to generate an new, separate reply annotation...

I create a file with a comment and a reply and then checked the box of the reply. I then ran this version of your first code on it:

this.syncAnnotScan();

var annots = this.getAnnots()

for ( var i= 0; i< annots.length; i++) {

    console.println(i+1);

    console.println("Type:"+annots.type);

    console.println("Text:"+annots.contents);

    console.println("Reply:"+(annots.inReplyTo=="" ? "false" : "true"));

    states = annots.getStateInModel("Marked");

    if ( states.length > 0 ) {

        for(j = 0; j < states.length; j++) {

            var s = states.state;    

            console.println("State:"+s);

        }

    }

    console.println("-----");

}

The results were:

1

Type:Text

Text:master comment

Reply:false

-----

2

Type:Text

Text:reply to master comment

Reply:true

State:Marked

-----

3

Type:Text

Text:Marked set by Gilad

Reply:true

-----

As you can see there are now two "reply" annotations, one that has the actual text I added, and another one that contains an automatic text that is generated when you check the box.

The weird thing is that only the first one has its state set as "Marked"... Another weird thing is that if I delete the master comment and the reply, that third one still remains, even though the Comments list is now empty.

1 reply

try67
Community Expert
Community Expert
March 31, 2016

Are you talking about a check-box? If so, it's not an annotation at all. It's a field, and you access its value like this (let's say its name is "CheckBox1"):

this.getField("CheckBox1").value

March 31, 2016

Nope, I'm talking about CheckMark inside a comment. Please see picture below

try67
Community Expert
Community Expert
March 31, 2016

I see what you mean. Unfortunately, I don't think you can access that information using a script.