Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

SOLVED

Passing a document to a trusted function

jonwater
Level 1
Level 1

[warning: newbie]

I am trying to put a save button on a livecycle document. It will create a filename based on some fields in the form.

I understand that I have to do this using a trusted function.

The example I found as a basis has the trusted function defined as:

var MySaveAs = app.trustedFunction( function(oDoc,cPath,cFlName)

{

    app.beginPriv();

    // Ensure path has trailing "/"

    cPath = cPath.replace(/([^\/])$/, "$1/");

    try{

        oDoc.saveAs(cPath + cFlName);

    }catch(e){

        app.alert("Error During Save");

    }

    app.endPriv();

});

and has the call defined like:

MySaveAs(this,cPath, "filename");

The reason I think this doesn't work, is that "this" in a static pdf form is a document object, and "this" in a livecycle form is the current object, which in this case is a button

("oDoc.saveAs is not a function" is the error I get in the console).

When you get to saveAs, oDoc is an XFA object and an xfa.Button doesn't have as saveAs method.

So the question is: What do I put as the first parameter in the call that is the current document object, so that the trusted function gets an object Doc and not an object XFAObject? Or is that my problem?

Thanks,

Jon

1 Accepted Solution
Martin_Grimm
Correct answer by
Level 1
Level 1

You are right in your analysis that "this" has a different value in XFA documents and AcroForm documents.

You should be able to use

MySaveAs(event.target,cPath, "filename");

in an XFA form instead.

For more information take a look at the documentation.

Hope that helps,

Martin

View solution in original post

2 Replies
Martin_Grimm
Correct answer by
Level 1
Level 1

You are right in your analysis that "this" has a different value in XFA documents and AcroForm documents.

You should be able to use

MySaveAs(event.target,cPath, "filename");

in an XFA form instead.

For more information take a look at the documentation.

Hope that helps,

Martin

View solution in original post

jonwater
Level 1
Level 1

Thanks Martin,

I think it would have taken me a long time with the documentation to work that out, though.

Jon