Expand my Community achievements bar.

Don’t miss the AEM Skill Exchange in SF on Nov 14—hear from industry leaders, learn best practices, and enhance your AEM strategy with practical tips.
SOLVED

How to embed an xml initial data in adobe LC form for dropdown controls.

Avatar

Level 7

Hi Developer,

I want to perform a POC to embed and Keep a xml data file for drop-down values. This xml is different from data xml. I have two xmls (xml1 & xml2).

Xml1 : This contains drop down values or initial values for the controls like Country Drop-down, List of Items drop-down. When I import this xml, I see my forms are filled up with these initial values in drop-downs. User can select values from drop-down, user can override already populated some of the values and also user can fill out fields like text fields, numeric fields. This xml1 is required as I do not want to hard code drop-down values in drop-downs so i preferred to keep it as xml so that I can ask admin user to update this xml without adobe LC designer skill.

Xml2: This is an XML which has only form data but no initial data or drop-down data. This xml contains only field data that user has filed in form by selecting either drop-down items or text/numeric fields. This data is usually obtained after importing Xml1 so that user can select items from drop-down values.

Note that, when I import xml1, I have only drop-down values or some initial values. But when i import Xml2, I just have values that User has ever filled and exported but without drop-down items.

Xml1 will be updated once in a while as drop down items doesn't get added or deleted very frequently.

XMl2 is user data so it will be different for each users.

I am looking for a solution to embed Xml1 in adobe LC pdf so that user always see those dropdown values in forms whether or not Xml2 is imported in form.

Currently, I am merging first element of root nodes of both xml to achieve this solution.

Question: Is there anyway that I can upload XML1 in form so that It resides always there and when user data XML2 is imported, dropdowns and other fields get selected/filled with xml2 data.

Link for sample forms :  XML1, XML2 and Embedded XML

Regards

1 Accepted Solution

Avatar

Correct answer by
Level 10

Hi Sunil,

The form submission xml is loaded under xfa.datasets.data, but you can also load other datasets under xfa.datasets and these won't affect the submission xml.

So a couple of ways of loading XML data into an alternative dataset is;

1 ... using code, for example this JavaScript in the preOpen event of the drop down list (uses E4X JavaScript extension to allow XML literals)

var caseXMLExport = <CaseXMLExport>
       <Races>
         <Race>
           <RaceId>10</RaceId>
           <RaceName>Asian</RaceName>
         </Race>
         <Race>
           <RaceId>11</RaceId>
           <RaceName>Bi-Racial</RaceName>
         </Race>
         <Race>
           <RaceId>2</RaceId>
           <RaceName>Black</RaceName>
         </Race>
       </Races>
     </CaseXMLExport>;
this.clearItems();
for each (var race in caseXMLExport.Races.Race) {
this.addItem(race.RaceName.toString(), race.RaceId.toString());
}


2 ... Editing the forms XML Source and adding XML directly under the xfa:datasets node,

<xfa:datasets xmlns:xfa="http://www.xfa.org/schema/xfa-data/1.0/">
   <xfa:data xfa:dataNode="dataGroup"/>

   <dd:dataDescription dd:name="CaseXMLExport"/>

   <CaseXMLExport>

      <Races>

         <Race>

            <RaceId>10</RaceId>

            <RaceName>Asian</RaceName>

         </Race>

  ...

      </Races>

   </CaseXMLExport>

</xfa:datasets>

In this case you need to set the Dropdown list item binding to xfa.datasets.CaseXMLExport.Races.Race[*] and you can't use the Designer UI as it doesn't know about the CaseXMLExport dataset.

This is a sample showing both methods  https://sites.google.com/site/livecycledesignercookbooks/home/XML%20Binding.pdf?attredirects=0&d=1

Regards

Bruce

View solution in original post

4 Replies

Avatar

Level 10

Hi,

with JavaScript you can create as mansy data nodes as you want under the xfa.datasets-node.

I'm using this method very often to update sets of data in my forms without the need of editing them in Designer again.

Here's an Action for Acrobat XI or later that allows you to import your XMLs either under xfa.datasets.data or xfa.datasets.

Dateien freigegeben - Acrobat.com

Avatar

Level 7

Hi Radzmar,

Thanks for replying..

I know how to create nodes and manuplate xfa.datasets.data... nodes. But will i be able to upload/import both xmls (xml1 and xml2).

How do I embed XML1 in adobe LC form for forever.

In other words, I want to build a functionality to import both xmls in form. Currently, when I import xml2 after xml1, my xml1 data gets overridden by xml2.

plz. reply.. or let me know if my question is not clear.

regards

Sunil

Avatar

Correct answer by
Level 10

Hi Sunil,

The form submission xml is loaded under xfa.datasets.data, but you can also load other datasets under xfa.datasets and these won't affect the submission xml.

So a couple of ways of loading XML data into an alternative dataset is;

1 ... using code, for example this JavaScript in the preOpen event of the drop down list (uses E4X JavaScript extension to allow XML literals)

var caseXMLExport = <CaseXMLExport>
       <Races>
         <Race>
           <RaceId>10</RaceId>
           <RaceName>Asian</RaceName>
         </Race>
         <Race>
           <RaceId>11</RaceId>
           <RaceName>Bi-Racial</RaceName>
         </Race>
         <Race>
           <RaceId>2</RaceId>
           <RaceName>Black</RaceName>
         </Race>
       </Races>
     </CaseXMLExport>;
this.clearItems();
for each (var race in caseXMLExport.Races.Race) {
this.addItem(race.RaceName.toString(), race.RaceId.toString());
}


2 ... Editing the forms XML Source and adding XML directly under the xfa:datasets node,

<xfa:datasets xmlns:xfa="http://www.xfa.org/schema/xfa-data/1.0/">
   <xfa:data xfa:dataNode="dataGroup"/>

   <dd:dataDescription dd:name="CaseXMLExport"/>

   <CaseXMLExport>

      <Races>

         <Race>

            <RaceId>10</RaceId>

            <RaceName>Asian</RaceName>

         </Race>

  ...

      </Races>

   </CaseXMLExport>

</xfa:datasets>

In this case you need to set the Dropdown list item binding to xfa.datasets.CaseXMLExport.Races.Race[*] and you can't use the Designer UI as it doesn't know about the CaseXMLExport dataset.

This is a sample showing both methods  https://sites.google.com/site/livecycledesignercookbooks/home/XML%20Binding.pdf?attredirects=0&d=1

Regards

Bruce

Avatar

Level 7

Hi ACP,

Thanks for for sending me above code. That really helped me another. After learning what you did.

As show in below snapshot, I uploaded Xml1.xml file for dropdowns, read it and loaded at dataset node using code..

var inputStream = event.target.getDataObjectContents("Xml1.xml");

var str=util.stringFromStream(inputStream);

xfa.datasets.loadXML(str,false,false);

TextField1.rawValue=xfa.datasets.CaseXMLExport.saveXML("pretty");

Not i put xfa.form.remerge(); on click on Remerge and I see data is papulated in dropdown..

xmlExport.JPG

Please find the files at link : Attachments