Manage Learn to apply best practices and optimize your operations.

Dynamic child table with line wrapping

Oftentimes we need to show "child" data as a table on a "parent" document.

Oftentimes we need to show "child" data as a table on a "parent" document. Embedded views can work with this, but they do not print. An tried-and-true method is to create a table with multi-value fields in the columns with the NewLine display separator. This works well except when one of the elements in one of the fields line wraps.

With this code, the designer controls the wrapping. This code also puts placeholders in the other columns if one column wraps. To use this code you must specify the target (parent) field names in a variant array. These fields should allow multivalues, have NewLine as the multivalue display separator, and also have NewLine as the only entering separator. You also must specify the wrapping character length. The view containing the child documents must be specified as well as the key (hopefully relating the children to the parent) as the first column of the view. Then either the child doc field names relating to the targetfields, or a view column value (of the format "^COL~n" must be specified for each of the target fields. A format for each target field must be specified: either "~" for text (wrapping might occur), or a string value to be used in a Format$ statement (for pseudo-numeric values - all values in the target multivalue fields are text). If you specify a format other than "~", the code will assume that the underlying data is numeric. You can optionally specify a field to total (one of the target fields). You also must specify the target document. Hope this helps someone!


 Setup: @SetProfileField("GLOBAL"; "PSTargetFields"; "Dates":"Projects":"Subprojects":"Hours":"Locations":"Descriptions"); @SetProfileField("GLOBAL"; "PSTargetLengths"; 9 : 15 : 20 : 0 : 20: 30); @SetProfileField("GLOBAL"; "PSSourceFields"; "^COL~2": "^COL~3": "^COL~4": "^COL~5": "^COL~6" :"^COL~7"); @SetProfileField("GLOBAL"; "PSTargetFormats"; "~": "~": "~": "0.00": "~" :"~") Call: Sub Initialize Dim s As New NotesSession Dim db As NotesDatabase Dim pdoc As NotesDocument Dim psdoc As NotesDocument Dim uiws As New NotesUIWorkspace Dim uidoc As NotesUIDocument Dim docid As String Dim cdoc As NotesDocument Dim detailvu As NotesView Dim key As String Dim wd As String Set db = s.CurrentDatabase Set uidoc = uiws.CurrentDocument Call uidoc.Refresh Set cdoc = uidoc.Document docid = cdoc.UniversalID Set detailvu = db.GetView("POINTENTRIES") Set pdoc = db.GetProfileDocument("GLOBAL") 'uidoc.AutoReload = False wd = Cstr(cdoc.WeekDialog(0)) Call maketable(detailvu, Cstr(cdoc.GetItemValue("Key")(0)), pdoc.GetItemValue("PSTargetFields"), pdoc.GetItemValue("PSTargetLengths"), pdoc.GetItemValue("PSTargetFormats"), pdoc.GetItemValue("PSSourceFields"), cdoc, "Hours") Call uidoc.Reload 'Call uidoc.Refresh 'uidoc.AutoReload = True Call uidoc.Save Call uidoc.Close Set cdoc = Nothing Set psdoc = db.GetDocumentByUNID(docid) Set uidoc = uiws.EditDocument(False, psdoc) End Sub Actual Routine: Sub maketable(view_in As NotesView, key_in As String, targetfields As Variant, targetlengths As Variant, targetformats As Variant, sourcefields As Variant, targetdoc As NotesDocument, totalfield As String) Dim tempsourcedoc As NotesDocument Dim currlengths() As Integer Dim items() As NotesItem Dim i As Integer Dim currmax As Integer Dim parsestring As String Dim tempchar As String Dim tempcounter As Integer Dim foundsplit As Integer Dim splittext As String Dim reptext As String Dim j As Integer Dim tempstart As Integer Dim total As Double Dim totalformat As String Dim colindex As Integer Dim numvalue As Double reptext = "." total = 0 Redim currlengths(0 To Ubound(targetfields)) For i = 0 To Ubound(currlengths) currlengths(i) = 0 Next Redim items(0 To Ubound(targetfields)) currmax = 0 Set tempsourcedoc = view_in.GetDocumentByKey(key_in, True) Do While Not tempsourcedoc Is Nothing If Cstr(tempsourcedoc.ColumnValues(0))<>key_in Then Exit Do End If For i = 0 To Ubound(targetfields) If targetformats(i) = "~" Then If Left$(sourcefields(i),4) = "^COL" Then colindex = Cint(Right$(sourcefields(i),Len(sourcefields(i)) - 5)) parsestring = Cstr(tempsourcedoc.ColumnValues(colindex)) Else parsestring = Cstr(tempsourcedoc.GetItemValue(sourcefields(i))(0)) End If Do While Len(parsestring)>Clng(targetlengths(i)) foundsplit = False For tempcounter = Clng(targetlengths(i)) To 1 Step -1 tempchar = Mid$(parsestring, tempcounter, 1) Select Case tempchar Case " " foundsplit = True Exit For Case "-" foundsplit = True Exit For Case "," foundsplit = True Exit For Case Else End Select Next If Not foundsplit Then tempcounter = Clng(targetlengths(i)) End If splittext = Left$(parsestring, tempcounter) parsestring = Right$(parsestring, Len(parsestring)-tempcounter) If currlengths(i) = 0 Then Set items(i) = targetdoc.ReplaceItemValue(targetfields(i),splittext) Else Call items(i).AppendToTextList(splittext) End If currlengths(i) = currlengths(i) + 1 If currlengths(i) > currmax Then currmax = currlengths(i) End If Loop splittext = parsestring parsestring = "" If currlengths(i) = 0 Then Set items(i) = targetdoc.ReplaceItemValue(targetfields(i),splittext) Else Call items(i).AppendToTextList(splittext) End If currlengths(i) = currlengths(i) + 1 If currlengths(i) > currmax Then currmax = currlengths(i) End If Else If Left$(sourcefields(i),4) = "^COL" Then colindex = Cint(Right$(sourcefields(i),Len(sourcefields(i)) - 5)) numvalue = Cdbl(tempsourcedoc.ColumnValues(colindex)) Else numvalue = Cdbl(tempsourcedoc.GetItemValue(sourcefields(i))(0)) End If If targetfields(i) = totalfield Then total = total + numvalue totalformat = targetformats(i) End If If currlengths(i) = 0 Then Set items(i) = targetdoc.ReplaceItemValue(targetfields(i), Format$(numvalue,targetformats(i))) Else Call items(i).AppendToTextList(Format$(numvalue,targetformats(i))) End If currlengths(i) = currlengths(i) + 1 If currlengths(i) > currmax Then currmax = currlengths(i) End If End If Next For i = 0 To Ubound(targetfields) tempstart = currlengths(i) ' If currlengths(i)<>currmax Then For j = tempstart To (currmax) Call items(i).AppendToTextList(reptext) currlengths(i) = currlengths(i) + 1 Next ' End If Next Set tempsourcedoc = view_in.GetNextDocument(tempsourcedoc) Loop If totalfield<>"" Then currmax = currmax + 2 For i = 0 To Ubound(targetfields) If targetfields(i) <> totalfield Then tempstart = currlengths(i) For j = tempstart To (currmax-1) If currlengths(i) = 0 Then Set items(i) = targetdoc.ReplaceItemValue(targetfields(i),reptext) Else Call items(i).AppendToTextList(reptext) End If currlengths(i) = currlengths(i) + 1 Next End If Next For i = 0 To Ubound(targetfields) If targetfields(i) = totalfield Then If currlengths(i) = 0 Then Set items(i) = targetdoc.ReplaceItemValue(targetfields(i),"---") Else Call items(i).AppendToTextList("---") End If Call items(i).AppendToTextList(Format$(total,totalformat)) End If Next End If Call targetdoc.Save(True, True) End Sub

Dig Deeper on Domino Resources - Part 4

Start the conversation

Send me notifications when other members comment.

Please create a username to comment.

-ADS BY GOOGLE

SearchWindowsServer

Search400

  • iSeries tutorials

    Search400.com's tutorials provide in-depth information on the iSeries. Our iSeries tutorials address areas you need to know about...

  • V6R1 upgrade planning checklist

    When upgrading to V6R1, make sure your software will be supported, your programs will function and the correct PTFs have been ...

  • Connecting multiple iSeries systems through DDM

    Working with databases over multiple iSeries systems can be simple when remotely connecting logical partitions with distributed ...

SearchDataCenter

SearchContentManagement

Close