These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

Return a path -- app.getPath()

RonD
Registered: Feb 11 2010
Posts: 9
Answered

I want to use the value returned by app.getPath("user") in order to enable some functionality on a form created using LiveCyle. The functionality to be enabled is a Save As option using the following code I found on this forum and which, by the way, works great:

//Code contained in .js file on users machine
//DateTime function
function myDateString()
{

return util.printd("yyyymmdd_HHMMss", new Date());

}

// SaveAs Function
var mySaveDoc = app.trustedFunction(function(doc) {

app.beginPriv();

var myPath = app.getPath("user", "documents") + myDateString() + ".pdf";

// saveAs is the only privileged code that needs to be enclosed with beginPriv/endPriv
doc.saveAs(myPath);
app.endPriv();

});

A button on the form contains
event.target.mySaveDoc(event.target);
which initiates the save as and works perferctly.

However, I want this button to be available only when a certain user is viewing the PDF. I can determine from the app.getPath() function who the user is. My question is how can I get the result from app.getPath() into a variable which I can then parse for the info I need? This should be simple since it is being collected in the above code but I can not figure out how to get it into a variable I can look at.

Thanks,
Ron

My Product Information:
LiveCycle Designer, Windows
radzmar
Expert
Registered: Nov 3 2008
Posts: 1202
You can add a function to your folder level script, that checks the login name and returns the value to a form field (named LoginUserName in my example).
This field can be set to invisible so the users won't know about, but you can use its value for other functions.

var TrustMe = app.trustedFunction(function(doc){app.beginPriv(); var IdentField = this.xfa.form.Form1.Page1.LoginUserName;IdentField.rawValue = this.identity.loginName;  app.endPriv(); });

Put this script in the form:ready event of the form field to call the function from the folder level script.
event.target.TrustMe(event.target);

radzmar
LoveCycle Blog
Documents you need:
LiveCycle Designer ES2 Docs

RonD
Registered: Feb 11 2010
Posts: 9
radzmar,

Your code works great! Thank you for taking the time to look through posts and to respond. In case you're not aware of it -- coding experience like yours is invaluable to those of us who don't live and breathe javascript.

Many, many thanks!
RonD