Button to open new PDF and populate fields
Copy link to clipboard
Copied
I am guessing this is a 2 part question/answer:
1) I am looking to use a button to open a new pdf fillable form
2) When it opens that new form I want it to take the info on the form open and popluate certain fields
Is this possible?
Copy link to clipboard
Copied
It's possible but there are better and worse ways of accomplishing this. Will the second form always be known to you? In other words are the two forms always associated with each other?
Copy link to clipboard
Copied
Yes both forms will always be used. One is a quote form than when it needs to be updated to an other I wouild like the user to use the button to create an invoice that would auto populate with the needed fields.
Copy link to clipboard
Copied
Ok - Then you want to make the invoice template an attachment to the quote form. This will let you open it programmatically without a user being prompted to find the file on their hard drive and won't require a privileged context. The code below will give you a handle to the invoice document.
var invoiceDoc = this.openDataObject("invoiceTemplate.pdf");
You will need to add some code at the document level of the invoiceTemplate to disclose it to other documents so you can send it JavaScript.
this.disclosed = true;
From there it's just a matter of setting the field values.
invoiceDoc.getField("myField").value = this.getField("myField").value
Then you'll want to add some code to save the file.
Copy link to clipboard
Copied
Thanks for your help! I am very much a beginner so sorry for all the questions. I am trying the first part. I put the code you listed into the Document JavaScript, I add the Invoice tab and add the script changing the pdf name to what I have it saved as. I than went into the documnet action and added the second script you put in. Nothing happened. I am very much a beginner when it comes to coding so sorry for the questions
Copy link to clipboard
Copied
Check the JS Console (Ctrl+J) for errors.
Copy link to clipboard
Copied
You won't be able to use the code I entered verbatim except for the disclosed line. Those are examples.
I suggest you go here and read a bit before attempting to script two forms to talk to each other. It's not complicated but it's not trivial either.
Copy link to clipboard
Copied
This is the error I am getting:
TypeError: Invalid argument type.
Doc.openDataObject:1:Document-Level:Invoice
===> Parameter cName.
Copy link to clipboard
Copied
That means you specified the wrong data-object name.
To get the correct name run this code from the JS Console:
this.dataObjects[0].name
Copy link to clipboard
Copied
Got it thanks!...now on to step 2
Copy link to clipboard
Copied
Joel, So for the second part transferring data from one pdf to the other. Am i putting the below script in the original pdf (one I am exporting the data from) or the new pdf (one I want teh data imported to)?
invoiceDoc.getfield("myField").value = this.getField ("myField).value
invoicedoc (is that the attachemnt name? "myfield" i assume is the text field name i want to transfer over. Do I put this code right in the Action Mouse Down insert Java Script field?
Thanks in advance
Copy link to clipboard
Copied
When working with multiple documents it's not a good idea to use the "this" keyword, as you can't be certain to which one it points. Use a separate variable to refer to the original doc, like this:
var originalDoc = this;
And later on:
invoiceDoc.getField("myField").value = originalDoc.getField("myField").value;
Copy link to clipboard
Copied
And invoiceDoc is the name of the variable that's pointing to the Document object you opened using openDataObject.
Copy link to clipboard
Copied
The code to push the field values to the second form goes in the original. You'd add it right after the code that opens the attachment. If you want to be very clear about it in your code, prior to opening the attachment, add the line...
var sourceDoc = this;
invoiceDoc.getfield("myField").value = sourceDoc.getField("myField).value
That way regardless of which document is "on top" you'll always be referencing the source and the target.
Replace "myField" with the names of each field you want to push or use a loop to go through all the fields.
Copy link to clipboard
Copied
I am getting an error:
ReferenceError: NewInvoiceFormpdf is not defined
3:Field:Mouse Up
Any thoughts?
Copy link to clipboard
Copied
You need to post your full code.
Copy link to clipboard
Copied
var NewQuoteFormpdf = this;
NewInvoiceFormpdf.getField("Bill to Name").value = NewQuoteFormpdf.getField("Bill to Name").value;
I was just trying the first part before I keep going...
Copy link to clipboard
Copied
Where's the code where you open the attached file?
Copy link to clipboard
Copied
this.exportDataObject({cName: "New Invoice Form.pdf", nLaunch: 2});
Copy link to clipboard
Copied
It was not in the code you posted. Please post your FULL code.
Copy link to clipboard
Copied
See below screen shot:
Copy link to clipboard
Copied
exporting the attachment doesn't return a variable. Use my original code to open the attachment so you can reference it by the variable.
Copy link to clipboard
Copied
When I use your script the pdf does not open, see below
Copy link to clipboard
Copied
That's OK - You don't need to see it to populate the data. You only want to use Export at the end of the process.
Copy link to clipboard
Copied
So that is what I am using and it does not open up the new pdf (New Invoice Form). Not sure if it would populate it or not... I get the below:
Thanks again for your help


-
- 1
- 2