These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

Using JavaScript for XML exchange / form population & modification

tdavis34
Registered: Sep 20 2007
Posts: 6

Hello,
 
I want to have my XFA form connect to a server when the form is first opened and have the server return both XML data to populate the form as well as other custom XML I can use to dynamically add form fields to a given subform or manipulate their event handlers. In essence, I want to make it such that an XML feed from a custom server script I write can both populate the XFA form and modify its behavior. The XFA template file itself will have reader extensions enabled, such that end users can download the form, watch it auto-populate itself, save their form data locally within Adobe Reader and then transmit their signed changes back to the server when complete. Is this possible? From all I've read, it seems so, but it's tough to navigate all the documentation and figure out which methods work with XFA vs. AcroForms, which will be allowed through default security measures without going to an enormous amount of extra effort (I've given up on using the Net.HTTP object because of this). Isn't there a simple way in JavaScript to connect to a server, grab XML data (I would have complete control over this XML, so it could be structured any way it needed to be) and use it to populate a form? Also, this needs to be a generic solution, not a specific one, since I'll need to apply this methodology to a lot of different forms.
 
Thanks for any help!

My Product Information:
LiveCycle Designer, Windows
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
This is not a short and specific question. You need to do some training, read a lot, and create examples. But here are some clues.

1. Dynamic XFA forms are designed specifically for dynamic field creation. You can create fields in the template that are not vissible, or do not exist on the displayed form. Then using JavaScript you can make the fields visible, or create new instances of the fields. Read about it and try it out.

2. Forget about Net.HTTP. This object is about a useless at they get. The only reasonable way for a form to communcate with a server script is through the "doc.submitForm()" function, which does HTTP request/response.

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script

sconforms
Expert
Registered: Jul 10 2007
Posts: 92
There's another way to do this. Supposing your web service had methods that returned the data and the other custom XML you needed, you could create web service data connections to both of those methods. For the first connection, you would bind fields to data nodes in the response portion so that when the response is received, the data is automatically populated into the appropriate form fields.

For the second connection, the one that retrieves the custom XML, you would have the web service method return the XML (as a string) that you need, making sure that the root node is something other than "data". You would then bind the response of the connection to a hidden field on the form. When the form is initialized, you can execute the connection using

xfa.connectionSet.CustomXMLConnection.execute();

The response, which is the XML data, will be returned in the hidden field. Get the field's value and load it as XML into the form's Data DOM like this:

xfa.datasets.data.loadXML(HiddenField.rawValue, false, false);

The first "false" says that the root node shouldn't be ignored and the second "false" says that the data should be appended to the Data DOM rather than replace it (so that you don't lose the data you just imported with the first web service connection).

Now, you should be able to access your XML data like this:

xfa.datasets.data.CustomData...

xfa.datasets.data.CustomData.node.value should get you the value ("text") contained in text.

Stefan Cameron obtained his bachelor's degree with Honors in Computer Science at the University of Ottawa and is a Computer Scientist working on Adobe's LiveCycle server products, in particular on LiveCycle Designer ES for the past 5 years.