Home/Support/

Forums

This Question is Answered

9 Replies Last post: Oct 26, 2009 11:09 AM by jhcarrell  
jhcarrell User 41 posts since
Jul 15, 2009
Currently Being Moderated

Oct 20, 2009 9:33 AM

Trusted Function "Save As"

I've created the following .js file in the "C:\Program Files\Adobe\Acrobat 8.0\Acrobat\Javascripts" folder on my pc.

 

File name "MySaveAsPO.js"

 

//script text as follows

 

/* 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]"); //copied ("form1[0].header[0].NextPONumber[0]") from an example
    var av = Date1.rawValue; //this is the name of the one of the fields I'd like to add to the save as file name although I'd like to use two fields.
    var g = "/s/AfterHoursLog/" + av + log".pdf" //the path I'm trying to save to is a shared drive "S:\AfterHoursLog"

    var retn = mySaveAsPO(myDoc, g);

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

 

******************************

 

The script I have on the "save" button is as follows:

 

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

event.target.myTrustedSpecialTaskFunc100(event.target);

 

 


This is not working for me. What am I missing?  Should the .js file be saved to the Reader js folder as well seeing as end user will be using reader to complete the form?

 

Any help is greatly appreciated.

 

Thanks.

 

 

Niall O'Donovan Participant 722 posts since
May 9, 2008
Currently Being Moderated
3. Oct 20, 2009 1:52 PM in response to: jhcarrell
Re: Trusted Function "Save As"

Hi,

 

A couple of things:

 

You don't need this trusted function. It allows a form to access properties such as the login name, etc.

// folder level JavaScript to allow access to the identity object properties
trustedIdentity = app.trustedFunction( function (sProperty)
{
var iProperty = "";
app.beginPriv();
iProperty = identity[sProperty];
app.endPriv();
return iProperty;
});

 

The script in the .js accessing the fields in the form are not correct:

 

var vDate1 = event.target.xfa.resolveNode(topmostSubform[0].Page1[0].Date1[0]).rawValue.toString();
var vTime1 = event.target.xfa.resolveNode(topmostSubform[0].Page1[0].Time1[0]).rawValue.toString();

 

 

Firstly the main page in the form is not named, which makes referencing it difficult. If you call the page "page1", then remember that javascript is case sensitive.It should look something like this:

 

var vDate1 = event.target.xfa.resolveNode(form1[0].page1[0].Date1[0]).rawValue.toString();
var vTime1 = event.target.xfa.resolveNode(form1[0].page1[0].Time1[0]).rawValue.toString();

 

You will need to create a "Test" folder in the root directory "C:", as Acrobat will not create one for you.

 

Lastly it will not work in Reader unless the form is Reader Enabled.

 

See how you get on. I will try and look at it later,

 

Niall

Niall O'Donovan Participant 722 posts since
May 9, 2008
Currently Being Moderated
5. Oct 20, 2009 3:20 PM in response to: jhcarrell
Re: Trusted Function "Save As"

Hi,

 

A few things are going on. Here is the .js


// folder level JavaScript to allow Save As population of file name
mySaveAs = app.trustPropagatorFunction(function(myForm, path)
{
     app.beginPriv();
     var myForm = event.target;
     return rtn = myForm.saveAs(path);
     app.endPriv();
});

myTrustFunct = app.trustedFunction(function(myForm, path)
{
     app.beginPriv();
     
     var vDate1 = event.target.xfa.resolveNode(form1[0].Log[0].Date1[0]).rawValue.toString();
     //var vTime1 = event.target.xfa.resolveNode(form1[0].Log[0].Time1[0]).rawValue.toString(); // dosen't like the : in the time format

     var vPath = /c/Test/ + vDate1 +  Log for shift  + time in here but it dosen't like the time format  + .pdf;
     //console.println(vPath:  + vPath);

     var retn = mySaveAs(myForm, vPath);

     app.endPriv();

     return retn;
});

 

The main thing is that the saveAs function does not like the ":" in the time format and therefore falls over.

 

Also one of the variables was mistyped.

 

In the form one of the lines was missing a ";" and on  another there were two.

 

Good luck,

 

Niall

Attachments:
Niall O'Donovan Participant 722 posts since
May 9, 2008
Currently Being Moderated
7. Oct 21, 2009 2:57 PM in response to: jhcarrell
Re: Trusted Function "Save As"

Hi,

 

It's working here with the form and .js file in the last post.

 

There were a few issues with both the original form and .js which made the script fall over; however I can't remember them at this stage. So if you are calling the .js from a different form it is difficult to say what's wrong.

 

When previewing the form in Acrobat press Control+J to bring up the javascript console. When you click the button it may show up where the script is failing.

 

Here is where I copied the .js file and remember to restart Acrobat after putting the .js into the folder.

 

21-10-2009 21-56-36.png

 

Try that and see if that works. Otherwise you would need to repost the form and .js.

 

Niall

More Like This

  • Retrieving data ...