How do I aggregate multiple, varying, fields from multiple documents (source docs) for display (or How do I create a List of Dynamic Arrays)? (By ‘varying’, I mean the list of departments in the code below is not constant).
I have a solution which I don’t like, mostly because I have to loop through the source documents multiple times to get multiple fields and that takes lots of time in a Queryopen. Here it is:
Sub getMM(docPI As notesdocument)
'For each department (itm.Values is multi-value text field)
departments = itm.Values
Forall fld In departments
'These three fields represent columns of dynamic tables in the target document
Set itmPIRes = docPI.ReplaceItemValue(fld, "")
Set itmPITitle = docPI.ReplaceItemValue(fld & "_Title", "")
Set itmPIPhone = docPI.ReplaceItemValue(fld & "_Phone", "")
'collWR is Collection of source documents. Loop through them all for each new dept.
Set docWR = collWR.GetFirstDocument
While Not docWR Is Nothing
arry = docWR.GetFirstItem(fld).Values
Call itmPIRes.AppendToTextList(arry)
arry = docWR.GetFirstItem(fld & "_Title").Values
Call itmPITitle.AppendToTextList(arry)
arry = docWR.GetFirstItem(fld & "_Phone").Values
Call itmPIPhone.AppendToTextList(arry)
'next WR doc
Set docWR = collWR.GetNextDocument(docWR)
Wend 'Not docWR Is Nothing
'Get next department
End Forall 'fld In departments
End Sub
If I could create a List of dynamic arrays, this would be easier. I want to use List since the departments vary. Or is there an even better way (like maybe setting the fields from the source docs when they are changed?).
Subject: How do I aggregate multiple fields from multiple docs for display?
Jeff,
Have you seen Dallas Gimpel’s LSHashMap class that he so generously posted here on Notes.net? It’s a little more robust than a traditional Notes List object. I used it to create a multi worksheet excel report with multiple rows per sheet, by creating a hashmap of a hashmap of a hashmap. I don’t think you are trying anything nearly so complex.
Check it out–one of the most useful classes you will ever run across:
Subject: RE: How do I aggregate multiple fields from multiple docs for display?
Thanks for answering another of my questions, Brandt,
This could be just right for me. Can I talk you into posting a code snippet of how you used it?
I put it in a Lotusscript library called LSHashMap; I’ve included it and declard a couple of test variables:
Dim hsDept List As LSHashMap
Set hsDept("AD") = New LSHashMap
Set hsDept("MM") = New LSHashMap
Now I need to get hsDept(“AD”) to be 3 arrays (right?). But how?
Or I guess I could do this:
Dim hsDept List As LSHashMap
Set hsDept("AD") = New LSHashMap
Set hsDept("AD_Title") = New LSHashMap
Set hsDept("MM") = New LSHashMap
Set hsDept("MM_Title") = New LSHashMap
Subject: RE: How do I aggregate multiple fields from multiple docs for display?
Jeff,
The LSHashMap class has a PutElement method that allows you to pass a variant to the HashMap. So when adding your array you would do so like this:
Call LSHashMap.PutElement(False,keyString,array)
I don’t see a reason why you would need more than one hashmap to accomplish what you are doing–simply place everything in the hash and then when you go to build your dynamic content, use the GetNthElement method combined with a For loop that goes from 0 to LSHashMap.Size - 1 (because LSHashMap.Size is 1 and not 0 based.)