Expand my Community achievements bar.

Guidelines for the Responsible Use of Generative AI in the Experience Cloud Community.
SOLVED

Save As Script with predefined path and file name

Avatar

Former Community Member

Hello,

Livecycle version: 8.2.1.4029.1.523496

The aim of the script I have is to save the livecycle form to a predefined directory and using the values of a text field in the file name.

The script is placed in an exit event on a field using javascript as follows:

this.saveAs("/c/forms/Template/Leave Application "  + Applicants_Name.rawValue".pdf");

The script does not work.

Can any one please provide some assistance with correcting my script?

Any help will be most appreciated.

1 Accepted Solution

Avatar

Correct answer by
Former Community Member

The only way to so a SaveAs is by Trusted Folder-Level Script.

Create a javascript file (Config.js) in the Javascripts directory (usually C:\Program Files\Adobe\ Acrobat x.0\Acrobat\Javascripts, where x=the version of Acrobat you have installed).  In the .js file, put something like

// SaveAs Function1

var mySaveDoc = app.trustedFunction(function(doc) {

app.beginPriv();

var myPath = "/c/temp/" + "WhateverNameYouLike" + ".pdf";

// saveAs is the only privileged code that needs to be enclosed

// with beginPriv/endPriv

doc.saveAs({cPath: myPath,

bCopy: true,

bPromptToOverwrite: false});

app.endPriv();

});

Call the function like event.target.mySaveDoc(event.target); using javascript in a mouse up event of a button.

I hope this helps.

View solution in original post

6 Replies

Avatar

Level 6

app.execMenuItem("SaveAs"); is the code to open SaveAs dialog never tried with specified path....you can explore more and happy to share your findings...

Avatar

Former Community Member

Thank you for your reply.

I have changed the script from this.saveAs to event.target.saveAs as follows:

event.target.saveAs("/c/forms/Template/Leave Application " + Applicants_Name.rawValue + ".pdf");

I now get the error as follows:

NotAllowedError: Security settings prevent access to this property or method.

Can you please offer any advice on if a trusted function would fix this, and how to use trusted function with saveAs?

Thank you.

Avatar

Correct answer by
Former Community Member

The only way to so a SaveAs is by Trusted Folder-Level Script.

Create a javascript file (Config.js) in the Javascripts directory (usually C:\Program Files\Adobe\ Acrobat x.0\Acrobat\Javascripts, where x=the version of Acrobat you have installed).  In the .js file, put something like

// SaveAs Function1

var mySaveDoc = app.trustedFunction(function(doc) {

app.beginPriv();

var myPath = "/c/temp/" + "WhateverNameYouLike" + ".pdf";

// saveAs is the only privileged code that needs to be enclosed

// with beginPriv/endPriv

doc.saveAs({cPath: myPath,

bCopy: true,

bPromptToOverwrite: false});

app.endPriv();

});

Call the function like event.target.mySaveDoc(event.target); using javascript in a mouse up event of a button.

I hope this helps.

Can you use for the file name a value from your pdf form? 

Ex: I have a field call "adress" and I whant the value contain in the field "adress" to appear in the file name.

Thank You

Avatar

Former Community Member

Thank you very much for your help.

I have created a folder level javascript and referenced the event.target.mySaveDoc(event.target); in the exit event of the field.

The leave form will now save to the users local c drive.

Your kind assistance is most appreciated.

Avatar

Level 6

This solution is misleading....

Of course this works only if you plan to load Trusted script on each machine you plan to use that form. In other words you can not rollout form to entire organization with out loading trusted function in each targeted machine.

Also there are other limitations... like if for some reason user reinstalls Acrobat x or Reader x or upgrade to latest version they need to remember to redeploy the trusted function to the required location.

The following has evaluated to null or missing: ==> liqladmin("SELECT id, value FROM metrics WHERE id = 'net_accepted_solutions' and user.id = '${acceptedAnswer.author.id}'").data.items [in template "analytics-container" at line 83, column 41] ---- Tip: It's the step after the last dot that caused this error, not those before it. ---- Tip: If the failing expression is known to be legally refer to something that's sometimes null or missing, either specify a default value like myOptionalVar!myDefault, or use <#if myOptionalVar??>when-present<#else>when-missing. (These only cover the last step of the expression; to cover the whole expression, use parenthesis: (myOptionalVar.foo)!myDefault, (myOptionalVar.foo)?? ---- ---- FTL stack trace ("~" means nesting-related): - Failed at: #assign answerAuthorNetSolutions = li... [in template "analytics-container" at line 83, column 5] ----