Expand my Community achievements bar.

SOLVED

Trusted Function "Save As"

Avatar

Level 3

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.

1 Accepted Solution

Avatar

Correct answer by
Level 10

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

View solution in original post

9 Replies

Avatar

Level 3

I've made the following script changes:

/* 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].#subform[0].Date1[0]");
    var av = a.rawValue;
    var g = "/s/AfterHoursLog/" + av + ".pdf"

    var retn = mySaveAsPO(myDoc, g);

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

The code still doesn't do anything however.

Any thoughts?

Thanks.

Avatar

Level 3

After reading a similar thread here > http://forums.adobe.com/message/2268179#2268179 I'm wondering if I'm going about this the wrong way.

I've attached an example form and js file I've saved to > C:\Program Files\Adobe\Acrobat 8.0\Acrobat\Javascripts

     If anyone can help me out with this I'd greatly appreciate it.

All form scripting is on the submit button which performs the following actions

Validate required fields // if pass perform the following  (THIS WORKS)

Lock all fields (THIS WORKS)

Hide Submit Button (THIS WORKS)

Email Form (THIS WORKS)

Execute Trusted Function Save As (THIS DOES NOT WORK)

Auto Close form (THIS DOES NOT WORK WITH THE TRUSTED FUNCTION SCRIPT ADDED)

Avatar

Level 10

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

Avatar

Level 3

I removed the trusted identity function as suggested.

Changed the subform name from (unnamed) to "Log" in the form.

Edited the js file per your suggestion to read:

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

C:/Test has already been created.

Upon clicking Submit all scripts fire excluding the save as event and auto-close (which follows the save as).

Thanks for stepping in to try and help me right the ship.  Any additional help would be equally appreciated.

Thanks.

Avatar

Correct answer by
Level 10

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

Avatar

Level 3

I removed the vTime1 variable in an effort to make it work with only using the vDate1 variable to establish the file name.

This was unsuccessful however.  What could I be missing?

I've saved the file to the Acrobat Pro JS folder, I'm using Acrobat Pro to complete the form, but with no success.

Any thoughts?

Avatar

Level 10

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.

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

Niall

Avatar

Level 3

Success!!

Thanks for your time and help.  It is greatly appreciated.

Jonathon