Passing a document to a trusted function

Avatar

Avatar

jonwater

Avatar

jonwater

jonwater

28-03-2013

[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

Accepted Solutions (1)

Accepted Solutions (1)

Avatar

Avatar

Martin_Grimm

Avatar

Martin_Grimm

Martin_Grimm

28-03-2013

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

Answers (1)

Answers (1)

Avatar

Avatar

jonwater

Avatar

jonwater

jonwater

28-03-2013

Thanks Martin,

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

Jon