Highlighted

Javascript conversion question - SaveAs

Avatar

Guest

17-12-2008

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...

Replies

Highlighted

pguerett

17-12-2008

The doc object is not valid in XFA Forms ...it needs to be changd to event.target. I do not know what the path is but it looks suspect to me. The this reference in the last line is a reference to th edoc obejct so that must be replaced as well.
Highlighted

Avatar

Guest

18-12-2008

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...
Highlighted

pguerett

18-12-2008

Your issues are in this code:



var a = event.target.xfa.resolveNode("form1[0].header[0].NextPONumber[0]");

var av = a.value;

var g = "/c/POSave/" + av + ".pdf



I would change it to this:



var av = from1.header.NextPONumber.rawValue

var g = "/c/POSave/" + av + ".pdf
Highlighted

Avatar

Guest

18-12-2008

Yes, Paul's code is right on track, (thank you for your help with this, it is much appreciated)...here's what I did right before seeing his post:



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.rawValue;

var g = "/c/POSave/" + av + ".pdf"



var retn = mySaveAsPO(myDoc, g);





app.endPriv();

return retn;

});

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

Button on form (script in click event):



//calls trusted function in MySaveAsPO.js folder-level script

event.target.myTrustedSpecialTaskFunc100(event.target);

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



Voila!