Skip to main content
doobeedoobee
Known Participant
April 17, 2017
Answered

OpenDoc with array of filenames

  • April 17, 2017
  • 1 reply
  • 416 views

I am trying to create a function that opens PDFs using an array with the filenames :

         var listDocs = ["KOOS.pdf", "OKS.pdf"]

        var arrayLength = listDocs.length;

        for (var i = 0; i < arrayLength; i++) {

              var otherDoc = app.openDoc(listDocs, this);

              otherDoc.getField("Serial").value=otherDoc.getField("Serial").value+1;

              var pp = otherDoc.getPrintParams();

              otherDoc.print(pp);

              }

I am getting the error

NotAllowedError: Security settings prevent access to this property or method

It works if I just have a variable :

var listDocs = "KOOS.pdf"

and don't use the loop. It also works if I have an array with only one filename in it.

Thanks for your help

This topic has been closed for replies.
Correct answer try67

1. Change this line:

var otherDoc = app.openDoc(listDocs, this);

To:

var otherDoc = app.openDoc(listDocs, this);

Also, you should not be using the "this" keyword as it might change to point to the current file you're opening in your loop.

Instead, create a variable that points to the original file at the start of your code and use it instead of "this".

So add this line at the top:

var oldDoc = this;

And then replace all instances of "this" with "oldDoc".

And you might want to add a command that closes the file after printing it.

1 reply

try67
Community Expert
try67Community ExpertCorrect answer
Community Expert
April 17, 2017

1. Change this line:

var otherDoc = app.openDoc(listDocs, this);

To:

var otherDoc = app.openDoc(listDocs, this);

Also, you should not be using the "this" keyword as it might change to point to the current file you're opening in your loop.

Instead, create a variable that points to the original file at the start of your code and use it instead of "this".

So add this line at the top:

var oldDoc = this;

And then replace all instances of "this" with "oldDoc".

And you might want to add a command that closes the file after printing it.

doobeedoobee
Known Participant
April 17, 2017

Fantatsic. Thanks try67