Skip to main content
Inspiring
Nov 5, 2017 11:44 PM UTC
Answered

How to pass an fdf file name from from doc a to doc b and import the fdf to doc b

An fdf file has been exported from document A and saved. It’s location and name are constructed from two variables, path + myFilename + ".fdf".

I know that the file name and device independent path are correct.

I placed a hidden field in doc B to receive the value of path + myFilename + ".fdf".

Objective: after doc B opens I want doc B to import my saved fdf file.

I am assuming that I need to pass the value of path + myFilename + ".fdf" to a field in doc B, and then tell doc B to import that fdf file.

Here is the most recent of many unsuccessful attempts to achieve my objective.

//fields in doc A

var myFilename = this.getField("txt.ClientFileName").valueAsString;

var path = this.getField("txt.Path.Client").valueAsString;

var parentPath = this.getField("txtL.Path.Parent").valueAsString;

var forms = this.getField("txtL.Folder.Forms").valueAsString;

var docB = app.openDoc("" + parentPath + forms + "PowerOfAttorney_Seller.pdf");

var docBSource = docB.getField("txt.dataFile");    

docBSource.value = path + myFilename + ".fdf";   

docB.importAnFDF(docBSource.value);

Result: Doc B opens, but the value of path + myFilename + ".fdf" is not passed to docBSource  and the import fails.  Can someone please tell me where I'm going wrong?

This topic is closed to new replies. Start a new post to keep the conversation going.
try67
try67Correct answer
Community Expert
Nov 6, 2017 5:19 PM UTC

I added "this.disclosed = true" as a document script in doc B and  I am no longer receiving the error that docB is undefined, so it appears that doc B is now accessible from doc A scripts. However, the values that I want to pass from doc A to doc B are not passed. The last 3 lines of my script behave as described in the bolded comments below.

     var docBSource = docB.getField("txt.dataFile"); //this field receives the value of "/Macintosh"

     docBSource.value = path + myFilename + ".fdf"; //this value is not passed to docBSource

     docB.importAnFDF(docBSource.value); //this behaves as if it were just docB.importAnFDF( "/Macintosh")


Change the variable name of "path". There is a built-in property of the Document object with that name and it will conflict with your variable.

14 replies

ODuinnAuthor
Inspiring
Nov 6, 2017 7:09 PM UTC

All of these replies to my original post provided helpful & correct information. Thanks for all of the help. In particular:

  • the property "disclosed" needed to be set for doc B. That was accomplished by a document level script, which I did with this:      function disclosed(){this.disclosed = true};      which was added to doc B.
  • I needed to change the variable name of "path" because the word "path" is a Document object name that conflicted with my use of "path" as a variable name.

With those changes, the following script accomplishes the objective that I originally posed. If the script is not placed in a trusted function it returns a security warning asking if I trust the site of the fdf file to be imported, which is why it is now a trusted function.

I also wanted doc B to become the focus after the script executed, which I accomplished by adding  docB.bringToFront(); to the script below:

var openPOASeller = app.trustedFunction(function()

  {

  //fields in doc A

  var myFilename = this.getField("txt.ClientFileName").valueAsString;

  var folder = this.getField("txt.Path.Client").valueAsString;

  var parentPath = this.getField("txtL.Path.Parent").valueAsString;

  var forms = this.getField("txtL.Folder.Forms").valueAsString;

  app.beginPriv();

       var docB = app.openDoc("" + parentPath + forms + "PowerOfAttorney_Seller.pdf");

       var docBSource = docB.getField("txt.dataFile");

       docBSource.value = folder + myFilename + ".fdf";

       docB.importAnFDF(docBSource.value)

       app.endPriv();

  }

);

Translate
try67
Community Expert
Community Expert
Nov 6, 2017 8:24 PM UTC

Small tip: Don't use "this" in your trusted function. Pass a reference to the document using a parameter, by changing its definition to something like this:

var openPOASeller = app.trustedFunction(function(docA)  {

  //fields in doc A

  var myFilename = docA.getField("txt.ClientFileName").valueAsString;

etc.

Then you call it like this: openPOASeller(this);

Translate
ODuinnAuthor
Inspiring
Nov 7, 2017 1:38 AM UTC

Thank you. I will do that.

David

Sent from my iPhone

Translate
ODuinnAuthor
Inspiring
Nov 6, 2017 3:56 PM UTC

After checking the API reference I added "this.disclosed = true" in a page open action of the first page of docB. However, the API says that app.openDoc checks the disclosed property of the document before returning its Doc. I am doubtful that the page open script accomplishes that objective of making doc B accessible to scripts in doc A. I do not know how to set doc B to disclosed = true in the script below.

I changed my script to the following. Although doc B opens, line 8 below returns "docB undefined" and I am still at a loss as to how to accomplish the objective of opening doc B and having it import the fdf file.

1 //fields in doc A

2 var myFilename = this.getField("txt.ClientFileName").valueAsString;

3 var path = this.getField("txt.Path.Client").valueAsString;

4 var parentPath = this.getField("txtL.Path.Parent").valueAsString;

5 var forms = this.getField("txtL.Folder.Forms").valueAsString;

6   //open doc B and import the fdf file

7 var docB = app.openDoc("" + parentPath + forms + "PowerOfAttorney_Seller.pdf");

8 var docBSource = docB.getField("txt.dataFile");

9   docBSource.value = path + myFilename + ".fdf";

10 var docBImport = docB.importAnFDF(docBSource.value);

Translate
try67
Community Expert
Community Expert
Nov 6, 2017 3:58 PM UTC

You need to add the script that discloses the file as a doc-level script.

Translate
ODuinnAuthor
Inspiring
Nov 6, 2017 5:00 PM UTC

I added "this.disclosed = true" as a document script in doc B and  I am no longer receiving the error that docB is undefined, so it appears that doc B is now accessible from doc A scripts. However, the values that I want to pass from doc A to doc B are not passed. The last 3 lines of my script behave as described in the bolded comments below.

     var docBSource = docB.getField("txt.dataFile"); //this field receives the value of "/Macintosh"

     docBSource.value = path + myFilename + ".fdf"; //this value is not passed to docBSource

     docB.importAnFDF(docBSource.value); //this behaves as if it were just docB.importAnFDF( "/Macintosh")

Translate
Legend
Nov 6, 2017 2:05 PM UTC

So the previous question is important and the route to a solution, if there is one.

Translate
Legend
Nov 5, 2017 11:59 PM UTC

Does docB return a non-NULL value?

Translate
ODuinnAuthor
Inspiring
Nov 6, 2017 2:47 AM UTC

No, it does not.

David

Sent from my iPhone

Translate
Bernd Alheit
Community Expert
Community Expert
Nov 6, 2017 8:46 AM UTC

Did you set the property "disclosed" of doc B?

Translate