Expand my Community achievements bar.

Grouping and summation

Avatar

Former Community Member
This is what I currently have in the adobe designer:



Group field1 field2

A 1 0

A 1 0

A 0 1

A 0 1

A 1 0

B 0 1

B 0 1

B 1 0

C 1 0

C 1 0

C 0 1



Instead of listing out all rows, I want to group them and sum of the field1 and field2 values. The desired results should look like this:



Group field1 field2

A 3 2

B 1 2

C 2 1



Please help!
9 Replies

Avatar

Former Community Member
Something like this is certainly possible but I'm having difficulty understand your scenario.



What I understand is that your form has 30 fields (10 under each of 3 columns).







  • Are these fields in a table or are they simply laid-out in a grid fashion?





  • How are the fields being populated with data? Are they filled-in by a user or are they populated when the form is open via a Data Merge operation with an XML data file or via some other type of data connection?







Stefan

Adobe Systems

Avatar

Former Community Member
Stefan,<br /><br />Thanks for the respond. The fields are in a table (group, field1, and field2) and the data are populated from a xml data file. Here are the xml code (for example):<br /><br /><?xml version="1.0" encoding="utf-8"?><br /><root><br /> <section><br /> <record><br /> <group>A</group><br /> <field1>1</field1><br /> <field2>0</field2><br /> </record><br /> <record><br /> <group>A</group><br /> <field1>1</field1><br /> <field2>1</field2><br /> </record><br /> <record><br /> <group>B</group><br /> <field1>1</field1><br /> <field2>1</field2><br /> </record><br /> <record><br /> <group>B</group><br /> <field1>1</field1><br /> <field2>1</field2><br /> </record><br /> <record><br /> <group>B</group><br /> <field1>1</field1><br /> <field2>1</field2><br /> </record><br /> <record><br /> <group>C</group><br /> <field1>1</field1><br /> <field2>1</field2><br /> </record><br /> <record><br /> <group>C</group><br /> <field1>1</field1><br /> <field2>1</field2><br /> </record><br /> </section><br /></root>

Avatar

Former Community Member
Just letting you know I haven't given-up on this thread. I've created a sample but I'm waiting to get permission to add attachments to my posts in order to post it to this thread.



Stefan

Adobe Systems

Avatar

Former Community Member
Thanks Stefan. I will be waiting for the sample.

Avatar

Former Community Member
I can finally attach files to my posts so here it is. The Zip file contains the form (in Acrobat 7.0.5 Dynamic PDF format) as well as an XML data file which holds the data to import into the form (this data was taken from one of your earlier replies to this thread).



It took me a while to figure this one out simply because of a lot of event timing issues (when events fire as well as when changes specified within those events actually take place). In the end, I've got a solution that works.



Open the sample form in Acrobat. Click on the
Load Data button . This will open the Import Data dialog from which you should pick the XML data file included in the solution. The result will be the groupings and summations you're looking for.



This was achieved by iterating through data records in the data DOM after importing the data into the form and using the TableRow object's Instance Manager to generate new instances of the TableRow object for each grouping/summation.



The tricky part was how to get the code which groups the data to execute only once the data had been imported. This was achieved by placing that code on an invisible field's Validate event and using a combination of boolean properties to determine whether we should group the data when the Validate event would fire (because the Validate event fires when the form is first opened, as well as every time the form is modified and we don't want to group the data every time a Validate event fires).



The key was setting the ImportData text field's Comb property (a boolean property) just before importing the data because this property change would take effect immediately as opposed to only after letting Acrobat import the data and fire the Validate event. Note that the Comb property is a property of the AcroForm Field Object which represents the XFA Form Field Object in Acrobat's Scripting environment. That's why we need code like this to get to it:



event.target.getField("form1[0].#subform[0].ImportData[0]").comb


Note that this solution assumes that you're importing data into the form by selecting a data file to import in Acrobat (so all this is occurring on the client side). If, in your particular case, the data is being merged-in on the server and then the resulting form is being served to the client, then you wouldn't need to do all this "jumping through hoops". All you would need to do is take the code within the "//// Server-side START ////" and "//// Server-side END ////" delimiters inside the ImportData field's Validate event and put it into the form's (form1 in this case) Form:Ready event. That's it. Things obviously get quite difficult when we do everything on the client side.



If you have any questions, please let me know.



Stefan

Adobe Systems

Avatar

Level 2

Hi Stefan,

I have a similar requirement, Can you please attach the solution you figured out?

Many thanks,

Sandeep

Avatar

Former Community Member
Hi! I´m looking for a DataGrid control for my pdfs forms..reading your posts i asume it doesn´t exists...right? Building a table with text fields like you say will be the turn around solution?



Thanks for your help.

Avatar

Former Community Member
Carlos,



There's no notion of a Data Grid control in XFA nor in Acrobat. Therefore, tables are your best alternative.



Stefan

Adobe Systems

Avatar

Former Community Member
Thanks! I found this really interesting document about Adobe XML Form Object Model (PDF, 4.1M) at this URL: http://www.adobe.com/devnet/livecycle/designing_forms.html



Carlos