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

How to save docB with a script called from the docA script that opens docB

Engaged ,
Nov 17, 2024 Nov 17, 2024

Copy link to clipboard

Copied

I have a script in a pdf form (“docA” for this question) that opens docB (a form named “Checks.pdf”) and calls a docB document level function, PrintChecks().. The PrintChecks() function spawns checks listed on page 1 of Checks.pdf and then prints the spawned checks. After the checks print I want the folder level script "saveToClientFolder()" (called at the end of the PrintChecks() script) to save Checks.pdf to the client’s folder. However, instead of saving docB (Checks.pdf), saveToClientFolder() tries to save docA but throws the dreaded error “The file may be read-only, or another user may have it open. Please save the document with a different name or in a different folder.” [My focus is not on that error message.]

 

I tried removing saveToClientFolder.() from PrintChecks() and adding “docB.saveToClientFolder()” at the end of the script that opens docB, but get the same attempt to save docA and the dreaded error. If instead of either of those options I place this.saveToClientFolder() in a button mouse up script in docB, it works just fine, but requires the user to click the button after the checks are printed. 

 

Can someone help me achieve my objective, i.e. call saveToClientFolder() at the end of  PrintChecks() so that is saves docB instead of trying to save docA?

TOPICS
JavaScript

Views

123

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 ,
Nov 17, 2024 Nov 17, 2024

Copy link to clipboard

Copied

The functions you define are not usually a method of the document object, but they exist on their own. You need to pass a reference to the Doc object you want them to run it as an input parameter, like this:

saveToClientFolder(docB);

And then in your function you have something like this:

 

function saveToClientFolder(doc) {

// use the doc variable to save the file

doc.saveAs(...);

}

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
Engaged ,
Nov 17, 2024 Nov 17, 2024

Copy link to clipboard

Copied

I've used input parameters quite a bit and but doing that in this instance produces the same error message.  Along with what I detailed in my post  I did not say that folder level function saveToClientFolder() identifies the pdf being saved by "this.documentFileName" and appends that to the path to the client's folder. Recalling that savieToClientFolder() does save my form "Checks.pdf" to the client's folder, why then would it not suffice to use saveToClientFolder() at the end of the document level function PrintChecks()?

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 ,
Nov 18, 2024 Nov 18, 2024

Copy link to clipboard

Copied

- Is docB disclosed?

- Can you share the full code?

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
Engaged ,
Nov 18, 2024 Nov 18, 2024

Copy link to clipboard

Copied

Yes, docB is disclosed. To fix my typos in my last reply I was reminding that when called by a mouse up button action, the folder level script saveToClientFolder() successfully saves  "Checks.pdf" to the client's folder , but throws the error when called from a line in the document level function "PrintChecks()" in "Checks.pdf." 

Checks.pdf is opened by this script in docA: var docB = app.openDoc({cPath: pathAndForm, oDoc: this}); (where "pathAndForm" is the path plus the form "Checks.pdf"). Then that line in the docA script is followed by docB.PrintChecks(), which of course triggers the PrintChecks() function in Checks.pdf. The last line in PrintChecks() is "this.saveToClientFolder()" but throws the error “The file may be read-only, or another user may have it open. ... ."   I then removed saveToClientFolder() from PrintChecks() and added it to the docA script as docB.saveToClientFolder() but that failed, then in the docA script - both before and after docB.PrintChecks() - I tried "saveToClientFolder(form)" (where input parameter form == "Checks.pdf") and "doc" was added to the folder script as: saveToClientFolder(doc). None of those worked.

My work-around is to stop trying to call saveToClientFolder() when the docA script triggers PrintChecks(), and just add an app.alert at the end of PrintChecks() telling the user to click on the button that executes saveToClientFolder() successfully. 

.  

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
New Here ,
Nov 18, 2024 Nov 18, 2024

Copy link to clipboard

Copied

My documents are attached documents
Rajibhossain

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 ,
Nov 18, 2024 Nov 18, 2024

Copy link to clipboard

Copied

LATEST

Sorry, but without seeing the files and the full code I can't help any further.

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