Expand my Community achievements bar.

Dive into Adobe Summit 2024! Explore curated list of AEM sessions & labs, register, connect with experts, ask questions, engage, and share insights. Don't miss the excitement.

script code sample for looping through the records from xml data file in formCalc script

Avatar

Former Community Member
Hi
I have a xml data file which contains a sequence of repeating applicant data like given below


US





II


CEO
Mr

111111111

0000000111
GuarantorA


111

IN
11111





WILLIAMS1
R3

KENNETH1
City1GU
PA
1934-03-14
abcdefgh@xyz.com

GU

R

113 Lazlo LaneCA
Suite 3500CA
OaklandCA
TX
11345
AL


I want to assign a textfield with a value based on the value of coap_flag.
So i need to loop through all the record and check the value of coap_flag and then assign the textfield a value based on that.

I am new to Adobe livecycle...Please help me how it can be done.

I have developed something like this
foreach Item in ($record.applicant[*].coap_flag) do
test.value=Item
if(test.value=="MA")then
concat($record.applicant.first_name,$record.applicant.middle_name)endif
endfor
7 Replies

Avatar

Former Community Member
No need to go through script to do this. In the dataview create a new connection and import a sample data file or the corresponding schema. A heirarchy of your xml file will appear. Locate the coap_flag field and drag and drop it onto the field that you want to set. A binding between the field and the data node is now established (you can see this by looking at the binding tab and on the heirarchy an icoon showing that this node is boound appears). Thats it....import you data file and the value will end up in that field.

Avatar

Former Community Member
I think u r not clear with my problem. I have given above the applicant data hiaerarchy which is in my data file. I have lot of applicant data available in the xml file with with this hiaerarchy. I want to display only some applicant details in a text field based on the value of the coap_flag. So i want to loop and check all the Applicant coap_flag and if the coap_flag matches my value i should be able to display my values in the field.



Now I am not able to get the loop executed. I am only able to get the value of the first Applicant..



Please help me.

Avatar

Former Community Member
I am only getting the data value of first applicant in the applicant hierarchy . For example in the above example i am getting the value of first applicant coap_flag value i.e "GU". But i need ti check other applicants coap_flag values also to decide which applicant data i need to enter within the textfield.

Avatar

Former Community Member
It has been a while since I played with the multiple occurances in the data dom. If you post a sample data file I can create a form that will show you how to get access to the individual repeating nodes. You can post it to livecycle8@gmail.com.

Avatar

Former Community Member
Hi thanks for the reply<br /><br />Actually I was able to retrieve those multiple data instances of the same named node using the javascript code given below.<br /><br /> var oItems = this.resolveNodes("record.applicant[*].coap_flag"); <br /> var iItems = this.resolveNodes("record.applicant[*]");<br /> var test="";<br /> for(var i=0;i<oItems.length;i++)<br /> {if(oItems.item(i).value=="MA")<br /> {test = String.concat();<br /> }<br /> <br /> } <br /> this.rawValue=test;

Avatar

Former Community Member
Using the data you posted in the forum, I copied it a couple of times to give multiple records and used this code to extract the different values that you wanted. I had to wrap it in a <root> node that I called root (to make it valid XML). In my case I wrote the extracted values to a field, but in your case you can do whatever you want with them. Note that this was done in javascript:<br /><br />var currentElement;<br />var obj;<br /><br />//Get the nodes below the root node in the dataDom<br />obj = xfa.datasets.data.root.nodes;<br /><br />//Set an initial value for the textField<br />TextField1.rawValue = "The values of the coap_flag are: ";<br /><br />//Loop through the nodes in the obj set <br />for (i=0; i< obj.length ; i++){<br /> //set the currentElement to the 1st child node<br /> currentElement = obj.item(i);<br /> //Check to see if it is an applicant node<br /> if (currentElement.name == "applicant"){<br /> //It is an applican, now find the coap_flag node value and write it to the text field<br /> TextField1.rawValue += "\n" + xfa.resolveNode("xfa.datasets.data.root.applicant[" + i + "]").coap_flag.value;<br /> }<br />}