Skip to main content
PasGlop
Inspiring
October 25, 2017
Answered

Scan a document for collecting the values of some fields

  • October 25, 2017
  • 3 replies
  • 948 views

I created a document (I don't know how to upload a pdf, therefore you can access a sample via Dropbox : https://www.dropbox.com/s/fni2eur4t1w48qa/Data_collecting%20.pdf?dl=0) of several pages and I need to extract the value of a field which can appear on some of the pages.

These fields are named:

Source.0

Source.1

Source.2

etc.

Page one can start with the field Source.2

the following page can be free of such a field

The field Source.8 may appear on page 3

etc.

I am trying to scan each page for finding a field starting with "Source." and if found, to copy its value to another field starting with "Result." but with the same index :

Result.3 value = Source.2 value

Result.10 value = Source.10 value

etc.

Please pay attention : the fields "Source." contain fixed references and the displayed pages are issued from templates. Therefore, I need to know which reference fields appear ont the displayed pages, and then capture their value. The list of "Result" will show part of the fields with a value, and the others must stay empty.

Here below is the beginning of my story... but I miss too much knowledge to continue...

  

Can someone help me to finalize it ?

Many thanks in advance.

*********************************************************************

ATTEMPT to display the value in app.alert (!!! infinite loop !!!

**********************************************************************

var
nameField="";

for (var a
= 0; a < this.numPages; a++) {

for (var i
= 0; i < this.numFields; i++) {

              var
nameField=this.getNthFieldName(i);

              var f = this.getField(nameField);

              var str=nameField;

              var OK =
str.indexOf("Source.");

              if (OK > -1) {

                            app.alert(this.getField(nameField).value);

                                           //break;

                            }

              }

}

This topic has been closed for replies.
Correct answer PasGlop

@ Test Screen Name :

I have to keep the same name used in the templates.and I agree with you regarding the difficulty.

That is the reason why I'm kindly asking some help

3 replies

Legend
October 26, 2017

I recommend you forget about page numbers, and focus on fields. Since you generate the names you can use the name to discover whether it is interesting. If you MUST interest yourself in the page(s) upon which fields appear, you still iterate all the fields but for each field you can inspect the "page" property which is a number or array. This will be much more complicated.

PasGlop
PasGlopAuthorCorrect answer
Inspiring
October 26, 2017

@ Test Screen Name :

I have to keep the same name used in the templates.and I agree with you regarding the difficulty.

That is the reason why I'm kindly asking some help

Bernd Alheit
Community Expert
Community Expert
October 26, 2017

The loops are not infinite.

PasGlop
PasGlopAuthor
Inspiring
October 26, 2017

I am amazed: the sample available via Dropbox contains this code in the "action" of the button (I deactivated it with "//" on each line because of infinite loop. ( I tested it right now (PC) and I can still observe an inifinte loop...

Do you mean that you did not find an infinite loop using the file and the code ?

try67
Community Expert
Community Expert
October 26, 2017

I don't understand why the page number is important... Don't you just want to copy the value of "Source.X" to "Result.X"?

PasGlop
PasGlopAuthor
Inspiring
October 26, 2017

Thanks for your Answer.

you are right  : the page number has no importance.

try67
Community Expert
Community Expert
October 26, 2017

You can use this code to achieve it:

for (var i=0; i<this.numFields; i++) {

    var f = this.getField(this.getNthFieldName(i));

    if (f==null) continue;

    if (/^Result/.test(f.name)) {

        var fname2 = f.name.replace("Result", "Source");

        var f2 = this.getField(fname2);

        if (f2==null) {

            console.println("Error! Can't find: " + fname2);

        } else f.value = f2.value;

    }

}