Skip to main content
PasGlop
Inspiring
July 5, 2021
Question

How to close a document opened from attached documents

  • July 5, 2021
  • 4 replies
  • 2391 views

Hello.

I would like to close by script a document opened from an attachment of another document:

 

I tried with the following code :

this.fileToClose = app.openDoc("DocToClose.pdf",this);
this.fileToClose.closeDoc(true)

 

It works when the document is opened from anywhere, but not when it is an attachment.

Is there a way to do it similarly but for an attachment?

Many thanks in advance for your help.

 

 

This topic has been closed for replies.

4 replies

try67
Community Expert
Community Expert
July 5, 2021

You have to get a reference to this Document object in order to be able to close it.

If the file is disclosed then it should appear in the activeDocs array and then you would be able to close it from there. Otherwise you will have to open it yourself using a script, and maintain a variable that's pointing to it. I also suggest you examine the path property of the attached file to see how it referenced internally.

PasGlop
PasGlopAuthor
Inspiring
July 5, 2021

The file is disclosed and with this line, I can see the concerned file (among others) when I display the content of "aFiles" :

var aFiles = app.activeDocs.filter(function(a){return this.path!=a.path;}).map(function(a){return a.documentFileName;});

 

But, despite all my efforts today, I am unable to find the way to close THE document I need among all those are opened (the one opened from the master PDF with this code) :

this.exportDataObject({ cName: "TEST.pdf", nLaunch: 2 });

 

Could you tell me, please, where I can find a sample to read, learn and transpose? for now i'm completely stuck on this topic...

try67
Community Expert
Community Expert
July 5, 2021

If aFiles is not empty and contains that document as its first item then you all need to do is add this command:

aFiles[0].closeDoc(true);

Bernd Alheit
Community Expert
Community Expert
July 5, 2021

app.openDoc("DocToClose.pdf",this);

will open a document at the folder as the open document.

PasGlop
PasGlopAuthor
Inspiring
July 5, 2021

Indeed, there is no reason: I use this part to list all the documents for another functionality ... and I made a copy / paste too generous.

Bernd Alheit
Community Expert
Community Expert
July 5, 2021

Why does you set aFiles when you don't use it?