Copy link to clipboard
Copied
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?
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.
Copy link to clipboard
Copied
Does docB return a non-NULL value?
Copy link to clipboard
Copied
No, it does not.
David
Sent from my iPhone
Copy link to clipboard
Copied
Did you set the property "disclosed" of doc B?
Copy link to clipboard
Copied
CORRECTION: My apology: my debugger was turned off. Yes, var docBSource = docB.getField("txt.dataFile”); is returning the error “docB is undefined”
Copy link to clipboard
Copied
So the previous question is important and the route to a solution, if there is one.
Copy link to clipboard
Copied
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);
Copy link to clipboard
Copied
You need to add the script that discloses the file as a doc-level script.
Copy link to clipboard
Copied
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")
Copy link to clipboard
Copied
Is your path value formatted as a device independent path?
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
When you open a document via JavaScript, you are just creating an Object that represents the document, you are not displaying it so none of the page level scripts actually run. Instead, you need to add the code to set the disclosed property at the document level so that it runs immediately after the document loads and before your code has a chance to try to communicate to it from another document. The easiest way to do this is to create an Acrobat Action that injects the JavaScript for you and then run the action on all the files you need to be disclosed.
Copy link to clipboard
Copied
All of these replies to my original post provided helpful & correct information. Thanks for all of the help. In particular:
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();
}
);
Copy link to clipboard
Copied
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);
Copy link to clipboard
Copied
Thank you. I will do that.
David
Sent from my iPhone