All,
Full disclosure here, this is my first ever post to an Adobe message board, and I have been working with Adobe LiveCycle ES4 for about 2 solid months. I have a separate program that will send a report file (in this case an Excel file) to a shared network folder, and I would like to leverage that data into my Dynamic form. I have been using a XML tools add in, and developer tools in Excel to export an XML file I can use in LiveCycle.
Example Schema:
<?xml version="1.0" encoding="UTF-8" standalone="true"?>
-<Root xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
-<Row>
<Thing1>ABCD</Thing1>
<Thing2>1234</Thing2>
</Row>
-<Row>
<Thing1>DEFG</Thing1>
<Thing2>1357</Thing2>
</Row>
-<Row>
<Thing1>HIJK</Thing1>
<Thing2>2468</Thing2>
</Row>
Again my JavaScript brain is still in it's infancy, but in my form I theoretically want to import data and output a respective <Thing1> to at least one object text field, one called say <Thing1Field>. Maybe dynamic binding isn't at all what i need to do in this instance, please read on.
What I am hoping, or attempting, to do is have an end user type a number into a number field called "Thing2Field". They click a button to get the corresponding <Thing1> in the same row as a matching <Thing2> outputed to a text field called "Thing1Field". Make sense? My fruitless attempts:
Root.#subform[0]::initialize - (JavaScript, client)
xfa.host.messageBox("Please select data to import to form.","Attention", 3,1);
xfa.host.importData();
Root.#subform[0].Button1::click - (JavaScript, client)
<all of the stuff>
I continue to bang by virtual Javascript head against the wall in trying to figure out what <all of the stuff> could be and where to start. I am fairly certain if I can figure out how to get the imported data into a declared variable I can work that into a 'for' loop with some conditional statements in order to set the raw value of that text field. My vocabulary isn't the greatest yet and a lot of the methods people come up with are amazing. I am really looking for an example.
Some may ask why I am using the .importData(); method. Long term in building this form I would like to create a representative node in which this imported data goes into. I have read that importing data from XML goes directly into the root.data?? node. If you were to import a second file it would overwrite the original becuase how the method and the DOM is setup. The data file I am working with in this example updates not so frequently and is in a different 'system' than another data file I would like to import. This other file would update frequently and has a lot more data present, it wouldn't be bound to the form but I need to call on the data to populate certain fields from it.
I am aware LiveCycle allows multiple instances of database connections through SQL and such, which we are moving toward, however I need to get a current working model to allow us to prove viability. Any help you could provide would be of great assistance. Thanks in advance for your time.
Alex
Solved! Go to Solution.
The replace () is to remove unwanted contents from the XML outside the XML-elements to avoid problems in the processing. Especially comments with multoiple line can cause that the import fails.
A XML like …
<?xml version="1.0" encoding="UTF-8"?>
<form1>
<page1>
<!-- This is a comment -->
<subform1>
<Name>John Doe</Name>
<Value1>Lorem Ipsum</Value1>
<Value2>Sit Amet</Value2>
</subform1>
</page1>
</form1>
… will be formatted into …
<form1><page1><subform1><Name>John Doe</Name><Value1>Lorem Ipsum</Value1><Value2>Sit Amet</Value2></subform1></page1></form1>
That's what the variable vImportXML will look like.
Views
Replies
Total Likes
Hi, you might find this useful: LiveCycle Blog: XML per Skript in Adobe Reader importieren//Import XML via Script into Adobe Reader
It shows an way to import XML data into a PDF using JavaScript and works with Acrobat and also Reader.
Thank you for that reference. I have been reading up on this code block a little because I didn't recognize the .replace() command in there. I see it may be leveraging the EX4 extensions in acrobat. Is that correct? The purpose of the .replace function according to John Brinkman is:
"Oddly, E4X refuses to process the xml processing instruction at the front of an XML fragment. If it’s there, you will get a syntax error: “xml is a reserved identifier”. The workaround is to remove leading processing instructions with a regular expression such as:
sXML = sXML.replace(/^[\s\S]*?(<[^\?!])/, “$1”);" -J. Brinkman blog 22SEP2010
It seems to load the data into the form OK, but I am curious what would the string then look like in vImportXML? I would need to understand that variable if I am to write something that leverages the data in it correct? Thing1's and Thing2's from above are related in the XML to the same row. That sibling relationship is something I hope to leverage.
I can write a loop with an if statement condition that if no number matches messagebox a 'try again'. If the loop condition matches a Thing1 in vImportXML, I am am not sure how to output a sibling Thing2 to a 'thingField2'.
Views
Replies
Total Likes
The replace () is to remove unwanted contents from the XML outside the XML-elements to avoid problems in the processing. Especially comments with multoiple line can cause that the import fails.
A XML like …
<?xml version="1.0" encoding="UTF-8"?>
<form1>
<page1>
<!-- This is a comment -->
<subform1>
<Name>John Doe</Name>
<Value1>Lorem Ipsum</Value1>
<Value2>Sit Amet</Value2>
</subform1>
</page1>
</form1>
… will be formatted into …
<form1><page1><subform1><Name>John Doe</Name><Value1>Lorem Ipsum</Value1><Value2>Sit Amet</Value2></subform1></page1></form1>
That's what the variable vImportXML will look like.
Views
Replies
Total Likes
At the end of the day in order to get the drop down list to dynamically populate, the XML structure I was utilizing from the XML tools plug-in, in Microsoft Excel was creating the XML format I listed above. You could probably write an example to get rid of the individual <row> listed above by putting all of the <Thing1>'s together and <Thing2>'s together is what worked. Or if I wanted to maintain the relationship have <Thing1>CatInTheHat</Thing1> <Value1>Dr.Suess<Value1/>. I had to re-adjust my thinking on nodes and values in order to get this to work.
Radzmar was spot on as usual, using the importData() method is a little clunky and his solution to import the data as a string is a good viable alternative the way I was presenting the problem. Navigating the rules associated with the XML nodes is something I need to learn a lot more about.
Views
Replies
Total Likes
Views
Likes
Replies
Views
Likes
Replies