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

JavaScript conversion - SaveAs

wingateg3
Registered: Jan 7 2008
Posts: 25

The following script works on an Acroform as a folder level .js file, with an additional .js file to create Menu item to call the function (MyTrustedSpecialTaskFunc1), and using Acrobat Pro or Standard (not Reader)...

My question is, how would I convert this for use with a LiveCycle designed form...I have played around with it, but I seem to be missing some key step...

------------------------
/* saveAs Script */

mySaveAs = app.trustPropagatorFunction( function ( doc, path )
{
app.beginPriv();
return retn = doc.saveAs(path);
app.endPriv();
});
myTrustedSpecialTaskFunc1 = app.trustedFunction( function ( doc, path )
{
app.beginPriv();

var a = this.getField("NextPONumber");
var av = a.value;
var g = "/c/hrarchive/" + av + ".pdf"

var retn = mySaveAs(this, g);

app.endPriv();
return retn;
});

-------------------------------
Menu item script:

app.addMenuItem({ cName: "Submit Package to HR Archive", cParent: "Help", cExec: "myTrustedSpecialTaskFunc1()", nPos: 0});

--------------------------------

the field in the Designer form is: "form1.header.NextPONumber"...Thanks in advance...

My Product Information:
LiveCycle Designer, Windows
wingateg3
Registered: Jan 7 2008
Posts: 25
OK...after messing with the script (modifying field names, path, and function name to work with my specific LiveCycle designed form) and finding bits and pieces on forums, here is what I have come up with:

Folder-level JS:
---------------------------------
/* saveAsPO Script */



mySaveAsPO = app.trustPropagatorFunction( function ( myDoc, path )
{
app.beginPriv();
var myDoc = event.target;
return retn = myDoc.saveAs(path);
app.endPriv();
});
myTrustedSpecialTaskFunc100 = app.trustedFunction( function ( myDoc, path )
{
app.beginPriv();


var a = event.target.xfa.resolveNode("form1[0].header[0].NextPONumber[0]");
var av = a.value;
var g = "/c/POSave/" + av + ".pdf"

var retn = mySaveAsPO(myDoc, g);


app.endPriv();
return retn;
});
---------------------------------------------------------

Button-script (click action) on the form:

//calls trusted function in MySaveAsPO.js folder-level script
event.target.myTrustedSpecialTaskFunc100(event.target);

-----------------------------------------------------

This saves a PDF to the specified folder, but does not name the PDF correctly...instead of naming it whatever I type into the "NextPONumber" field, (i.e. PO#1234.pdf), it names it as :

[object XFAObject].pdf

Any ideas what is going on here? Thanks in advance...
wingateg3
Registered: Jan 7 2008
Posts: 25
OK...I think I have it...

In the above script (2nd post), this line:
var av = a.value;

needs to be replaced with:
var av = a.rawValue;

Voila!