MS Office Forum / General MS InfoPath Questions / September 2005
Merging Information from two repeating tables into one
|
|
Thread rating:  |
Mike - 06 Sep 2005 15:29 GMT I have three views in one form, the first view is a time sheet, second view is a parts list and third view is an invoice. All three views have repeating tables, all of which have a different layout.
I would like to query the data from the repeating table in the time sheet view, and query the data from the repeating table on the parts view and insert it into the invoicing repeating table.
I do know some VB Scripting and no J Scritping.
Can anybody help?
 Signature Mike Rottmann
Scott L. Heim [MSFT] - 07 Sep 2005 13:09 GMT Hi Mike,
The first question I have is this: where is your data being stored? For instance, did you create your InfoPath solution from a data source (i.e. Access, SQL Server or web service) or did you start with a blank form and simply add controls?
Based on your answer, I may have some additional questions.
Thanks,
Scott L. Heim Microsoft Developer Support
This posting is provided "AS IS" with no warranties, and confers no rights
Mike - 07 Sep 2005 14:14 GMT Scott,
I started with a blank form and added the controls. Our intention is to "extract" the information to an excel spreadsheet in upload into our finanical package.
 Signature Mike Rottmann
> Hi Mike, > [quoted text clipped - 11 lines] > > This posting is provided "AS IS" with no warranties, and confers no rights Scott L. Heim [MSFT] - 07 Sep 2005 14:56 GMT Hi Mike,
Thank you for the additional information. As you are probably aware, a "View" in InfoPath is exactly that: a "view" of your data. Since you are trying to "export" the data to Excel it may be easier to simply create a new View (i.e. named: vwExcelExport) where you pull all needed "groups" into this one "export" View. Does that make sense?
Now with that in mind, I want to make you aware of something that may or may not come into play: InfoPath is able to create hierarchical data structures (i.e. 1 -> Many) very easily. However, Excel would need to "flatten" that data structure in order to display the same information. All I am suggesting is that if you have not exported your current data structure to Excel yet you may want to do so just to be sure you get what you need for your other application.
I hope this helps!
Scott L. Heim Microsoft Developer Support
This posting is provided "AS IS" with no warranties, and confers no rights
Mike - 07 Sep 2005 15:07 GMT Scott,
Thank you for your quick responce.
I still have the issue of taking information from two repeating tables and inserting the information into a third one. The extract is later (after the trhird repeating table is populated).
The third repeating table is needed on the invoice view so that we can produce an invoice to the customer. The invoice repeating table combines the labor view and the parts view. The upload to our financial system will not happen until later.
 Signature Mike Rottmann
> Hi Mike, > [quoted text clipped - 18 lines] > > This posting is provided "AS IS" with no warranties, and confers no rights Scott L. Heim [MSFT] - 07 Sep 2005 15:36 GMT Hi Mike,
Ok - let me now get some additional information from you. In your initial post you indicated the layout of each repeating table is different - am I inferring correctly then that the data is also "different?" If so, how would you be able to combine this into one table?
Could you post some sample data and your structure from the 2 repeating tables so I can get a better idea of what you need?
Thanks,
Scott L. Heim Microsoft Developer Support
This posting is provided "AS IS" with no warranties, and confers no rights
Mike - 07 Sep 2005 15:54 GMT Scott,
Thanks for your quick responce. Here is the layout for the 1st table... Qty, Part No., Qty Picked, Qty Used, Qty left over, Qty Returned and Qty on Order
2nd table
Start Hour, Finish hour, Number of hours, Accommodations Cost, Substance Cost, Kilometers traveveled.
3rd table is as follows:
Qty, Item, Description, Price and Total.
The Qty would come from the number of hours on the second table, and the qty used from the first table
The item would be coded as "hours" from the second table and "Part No." from the first table.
The cost would be coded as a flat rate of $75.00 fro every reference in the second table and the part number will have another external XML data reference for every part in the first table.
The total will be a calculated field.
Hope this helps
 Signature Mike Rottmann
> Hi Mike, > [quoted text clipped - 12 lines] > > This posting is provided "AS IS" with no warranties, and confers no rights Scott L. Heim [MSFT] - 07 Sep 2005 16:18 GMT Ok - one additional question: is Table3 a "summation" only or for each row in Table1 and Table2 we need to have a corresponding row in Table3?
Scott L. Heim Microsoft Developer Support
This posting is provided "AS IS" with no warranties, and confers no rights
Mike - 07 Sep 2005 16:26 GMT First table is a line by line and the second table is a summation.
 Signature Mike Rottmann
> Ok - one additional question: is Table3 a "summation" only or for each row > in Table1 and Table2 we need to have a corresponding row in Table3? [quoted text clipped - 3 lines] > > This posting is provided "AS IS" with no warranties, and confers no rights Scott L. Heim [MSFT] - 07 Sep 2005 16:55 GMT Mike,
Please accept my apologies as I am confused: table1 is "multiple row (multiple line items) table. Table2 is a summation of Table1? In what way? Why would this one be a repeating table? And then what is Table3? Line items or summation?
You also indicated that the "Qty" field in Table3 is the "Number of Hours" from Table2 and the "Qty Used" from Table1. So if Table2 is a "summation" of Table1 is the "Number of Hours" field a "calculation" that totals the "Qty" field from Table1??
Again I am sorry but I am not clear on your structure here...
Scott L. Heim Microsoft Developer Support
This posting is provided "AS IS" with no warranties, and confers no rights
Mike - 07 Sep 2005 17:22 GMT Scott,
I can understand the confusion. Let's see if I can clear it up.....
Table 1, Table 2 and Table 3 are all repeating tables with footers which total the detail lines. Table 1, which is the time sheet view, I am only interested in the total line ( this is the summarized total line). In Table 2, I am interested in all of the details. Table 1 summary and table 2 details will be placed as line items in table 3.
If this makes it simpler, I am interested in how to programically read informtion from one repeating table, and put it into another repeating table. I have read an intersting artical on how to insert row into a repeating table by using the "Document.view.ExecuteAction "xCollection::insert","group2_1"" method. This work great in test. After I insert a row, how do I address inserting values into the table (and how do I read from another)?
 Signature Mike Rottmann
> Mike, > [quoted text clipped - 14 lines] > > This posting is provided "AS IS" with no warranties, and confers no rights Scott L. Heim [MSFT] - 07 Sep 2005 18:32 GMT Mike,
That does help! So now I am wondering if we can actually get you where you need to be without code!
What about this as an option:
- Table1 (with the summary fields) - Table2 - Table3 (bound to the same "group" as table2 - you can make this such that a user cannot enter/delete the items)
Now so far what this will do is as you add items to table2 they will automatically appear in table3 as well. However, at this point, we are still "missing" the summary items from table1. You could now add the columns you need to table3 by simply right-clicking on the last column (or any column for that matter) and choosing Insert -> Column. Lastly, you would add a text box to that new column and set the "Default Value" of this box to the same expression as your summary expression in table1.
What you now have is a duplicate of table2 with the added summary data from table1.
Does this make sense? Do you think this may be an option?
Scott L. Heim Microsoft Developer Support
This posting is provided "AS IS" with no warranties, and confers no rights
Mike - 07 Sep 2005 22:08 GMT Scott,
Interesting. If I have three items that are summerized from table 1, and with the solution that you present, will there be 3 detail items in the table 3?
 Signature Mike Rottmann
> Mike, > [quoted text clipped - 25 lines] > > This posting is provided "AS IS" with no warranties, and confers no rights Scott L. Heim [MSFT] - 08 Sep 2005 14:43 GMT Hi Mike,
Yes - with this assumption on my part:
- Let's assume table1 is as follows and has this data:
Name Hours Days Scott 8 1 Mike 40 5
-- 48 6
** NOTE: The "--" above simply denotes the summary data
- What I am suggesting is that table3 is "bound" to the same group as table2; however, once you do that you will now add 2 additional columns (right-click -> Insert -> Columns) to table3: one for "Total Hours" and one for "Total Days" where the "Default Value" field can be the same expression as the summary fields above - this way as you add detail items to table2 they will appear in table3 along with the summary information from table1.
Let me know if you need sample steps and I can provide those for you.
Scott L. Heim Microsoft Developer Support
This posting is provided "AS IS" with no warranties, and confers no rights
Mike - 08 Sep 2005 15:41 GMT Scott,
There is some more information that you do not know about. I have to read the table 1 and table 2 and recode the information for the invoice. As an example, the reg hours has to appear as "Regular Hours Worked" on table 3. Along with this, I have to code in the rate per hour to charge.
I think it would be ideal to programmically copy data from one repeating table to another. I need to know how to read and update rows in a table by the use of BV scripting. Is there anywhere where I can see how to do this? Can you help?
 Signature Mike Rottmann
> Hi Mike, > [quoted text clipped - 23 lines] > > This posting is provided "AS IS" with no warranties, and confers no rights Scott L. Heim [MSFT] - 08 Sep 2005 16:59 GMT Hi Mike,
No problem. I am going to be tied up for a bit today but did not want to leave you hanging on this. In a previous post (http://groups.google.com/group/microsoft.public.infopath/browse_thread/thre ad/96fe5ca27f92db15/41eb58cc879af2e7?lnk=st&q=InfoPath+Add+%22Repeating+Tabl e%22+VBScript&rnum=6&hl=en#41eb58cc879af2e7) someone needed to programmatically add rows to a repeating table. I realize this is not all you need to do but maybe this will help get you started in the mean time. There is sample VBScript in the above post that I provided...let me know if this helps get you going and where you still need some direction (if you indeed need more direction - that was bad of me to assume) and hopefully I can fill in the blanks for you.
Thanks Mike!
Scott L. Heim Microsoft Developer Support
This posting is provided "AS IS" with no warranties, and confers no rights
Mike - 08 Sep 2005 19:29 GMT Scott,
Thanks for the tip. I have already downloaded and tested the VB script. It works great. It is very simple and I have researched various options (i.e. removing rows). I also created the standard "Hello World" test with a button and a text box - and this also worked great. I just have problems in addressing the fields contained within the repeating tables. I am trying to figure out how to programically read and set the values within the repeating tables. Any help that you can give me would be great.
Thanks
 Signature Mike Rottmann
> Hi Mike, > [quoted text clipped - 16 lines] > > This posting is provided "AS IS" with no warranties, and confers no rights Scott L. Heim [MSFT] - 10 Sep 2005 01:17 GMT Hi Mike,
Sorry about the delay on this...
There are a number of ways one can get records from one repeating table to another; however, since you need to "massage" the data before copying it to the 2nd table it makes it a bit more interesting! :-)
Here are some sample steps to copy records from one repeating table into another repeating table.
- Create a new, blank InfoPath form - Add a Repeating table with 2 columns - Add a button below that table - Add another Repeating table with 2 columns - If you now look at your Data Source, you should see this:
- myFields - group1 - group2 - field1 - field2 - group3 - group4 - field3 - field4
- Right-click on the button, choose Properties and click Edit Form Code...you should see this (other than your button name will be different)
function btnCopyRecords::OnClick(eventObj) {
}
- In between the braces, add this code:
var objTable1 = XDocument.DOM.selectNodes("//my:myFields/my:group1/my:group2") var objXMLNodes; for(var i = 0;i <= objTable1.length - 1;i++) { var objTable2 = XDocument.DOM.selectSingleNode("//my:myFields/my:group3/my:group4[last()]") if(objTable2.selectSingleNode("my:field3").text != "") { XDocument.View.ExecuteAction("xCollection::insert", "group4_2"); } var objTable2 = XDocument.DOM.selectSingleNode("//my:myFields/my:group3/my:group4[last()]") var objT1CurrentRow = objTable1.item(i); objTable2.selectSingleNode("my:field3").text = objT1CurrentRow.selectSingleNode("my:field1").text objTable2.selectSingleNode("my:field4").text = objT1CurrentRow.selectSingleNode("my:field2").text }
- Save the code, Preview the form and test. After adding text to field1 and field2 in the table, click the button and those records should be copied to the bottom table.
Let me know if this is what you needed!
Best Regards,
Scott L. Heim Microsoft Developer Support
This posting is provided "AS IS" with no warranties, and confers no rights
Mike - 12 Sep 2005 17:40 GMT Scott,
It works. Thanks for your help.
Here is the code that I finally got to work with the your test form that suggested above:
dim objTable1 dim objTable2 dim objXMLNodes dim i set objTable1 = XDocument.DOM.selectNodes("//my:myFields/my:group1/my:group2") for i = 0 to objTable1.length -1 set objTable2 = XDocument.DOM.selectSingleNode("//my:myFields/my:group3/my:group4[last()]") if (objTable2.selectSingleNode("my:field3").text <> "") then XDocument.View.ExecuteAction "xCollection::insert","group4_2" end if set objtable2 = XDocument.DOM.selectSingleNode("//my:myFields/my:group3/my:group4[last()]") set objT1CurrentRow = objTable1.item(i) objTable2.selectSingleNode("my:field3").text = ObjT1CurrentRow.selectSingleNode("my:field1").text objTable2.selectSingleNode("my:field4").text = ObjT1CurrentRow.selectSingleNode("my:field2").text next
 Signature Mike Rottmann
> Hi Mike, > [quoted text clipped - 67 lines] > > This posting is provided "AS IS" with no warranties, and confers no rights "Scott Heim" - 12 Sep 2005 20:09 GMT Hi Mike,
That's great - thank you for the update!
Take care,
Scott L. Heim Microsoft Developer Support
This posting is provided "AS IS" with no warranties, and confers no rights
|
|
|