Copy link to clipboard
Copied
I have been tasked with the process of altering a fillable pdf form at work. The purpose of this form is for an employee here at the office to run this application and to select a proposal and it populate a list of classifications and wage rates, save the pdf form and then they can email that form to users in the field to fill out and return.
I am not really that familiar with fillable pdf forms but as a programmer feel I can handle it. The form I am trying to populate contains three columns; a classification field that I populate with selected dropdown items (I found this easy) and then an Hourly Rate Paid column that I am trying to populate dynamically when they select a classification and a number of employees column that they enter manually.
What I need the form to do is when a classification is selected from the dropdown (by the user in the field) the form is supposed to look through a dataset of some type and find that classification along with its related wage rate and then automatically populate the hourly rate paid. Everything I have read says if the users using the form aren't local then using a database isn't the best option. So, I thought on the original generating of the fillable pdf form, by the employee in the office, that I could query the database, store the data locally some how whether a dataset or a temp table or something and then when the user in the field gets the form and selects a classification that it uses that local table/dataset to find that value.
I am able to create a temp table in the vb code of the application but have no idea how to call that table within the javascript editor.
Here is the function I wrote for pulling the data into a local table
Private Function Classifications_values(ByVal classifications As List(Of Model.V_WAGE_DECISIONS))
Dim classification_value As New DataTable
classification_value.Columns.Add("Classification")
classification_value.Columns.Add("Value")
For Each i In classifications
Dim itm As Model.V_WAGE_DECISIONS = i
Dim row As DataRow = classification_value.NewRow
row(0) = i.DESCR
row(1) = i.WAGE_RATE
classification_value.Rows.Add(row)
Next
Dim ds As New DataSet
ds.Tables.Add(classification_value)
Return ds
End Function
And in javascript of the pdf form I set up a document JavaScript called SetFieldValues and did this:
function SetFieldValues(classification)
{
this.getField("Hourly Rate Paid").value = classification_value[classification].Value;
}
If I replace "classification_value[classification].Value" with the number 12 it works perfectly but it won't query the table/dataset.
Any suggestions would be appreciated. Thanks!
Copy link to clipboard
Copied
First of all, I moved your question to the JavaScript , where it more naturally belongs.
Regarding your question: Connecting an Acrobat form to a DB, local or otherwise, is impossible.
The data will have to be embedded in the file itself (in the form of a plain-text file, for example), or read dynamically from a local (also plain-text) file. The latter option requires installing a script on the local machine of each user, as well as the data file itself, so it's probably a less desired solution.
If the data is attached to the file then a script can be used to read it, parse it and then populate the other fields when a selection is made in one of the drop-downs. This is a pretty advanced scripting task, though, and requires you to be familiar with data objects (the technical name for attachments), string manipulation and field-triggered scripts.
Copy link to clipboard
Copied
Thank you for putting me in the right place. I wasn't 100% sure where to post. I appreciate that.
This leads me in a general direction which is what I really needed. I will do some more digging into parsing a plain-text file and see if I can get it figured out. If not, I may go another direction with it! Thanks!
Copy link to clipboard
Copied
I was able to get the code working thanks to your information above. I created an XML file and embedded it within my PDF. Then wrote the following javascript to populate the value based upon the selected classification. I added a validation on the value field because the user is not allowed to enter a value less than the value that is originally placed in that field. It works good except for the fact that if I select classification 1 and it populates 12, then I select classification 2 and it populates 14.. if I select classification 1 again it throws the validation error. I tried to place clearing code in keystroke change of the classification field to clear out the value before changing the classification to see if that would help but no luck. Any suggestions?
Keystroke for Classification Field
this.getField("Hourly Rate PaidRow1").value = null;
var file;
file = this.getDataObject("Classification_Values.xml");
var file_contents;
file_contents = this.getDataObjectContents("Classification_Values.xml");
var xml_output;
xml_output = util.stringFromStream(file_contents, "utf-8");
var myXML;
myXML = XMLData.parse(xml_output,false);
var itm;
itm = XMLData.applyXPath(myXML, "//NewDataSet/Table1/Classification");
var itm_value;
itm_value = XMLData.applyXPath(myXML, "//NewDataSet/Table1/Value");
var i;
var classification;
classification = event.value;
var control;
control = "Hourly Rate PaidRow1";
for (i = 0; i < itm.length; i++) if (itm.item(i).value == classification) {this.getField(control).value = itm_value.item(i).value};
Custom Validation Script for Value Field
var file;
file = this.getDataObject("Classification_Values.xml");
var file_contents;
file_contents = this.getDataObjectContents("Classification_Values.xml");
var xml_output;
xml_output = util.stringFromStream(file_contents, "utf-8");
var myXML;
myXML = XMLData.parse(xml_output,false);
var itm;
itm = XMLData.applyXPath(myXML,"//NewDataSet/Table1/Classification");
var itm_value;
itm_value = XMLData.applyXPath(myXML, "//NewDataSet/Table1/Value");
var i;
var classification;
var itm_min_value;
classification = this.getField("Dropdown1 - Class").value;
for (i = 0; i < itm.length; i++) if (itm.item(i).value == classification) {itm_min_value = itm_value.item(i).value};
if (event.value != "" && event.value < itm_min_value) {app.alert("The minimum hourly paid rate allowed for the selected
classification is " + itm_min_value); event.value = itm_min_value;};
Copy link to clipboard
Copied
Acrobat JavaScript can't access the table in the VB code.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now