#Description: Example code to update a Bookmark to include an Electronic Signature block suitable for Secured Signing.
#Author: Intersoft Systems Limited
#Version: 1.00
#Last Updated: 26/05/2017

Dim AccountClient As finAccountClient
Dim Count As Integer
Dim Email As String
Dim ESignatureSmartTag As String
Dim SummaryTable As ISSummaryTable
Dim SummaryTables As ISSummaryTables

' Initialise
Count = 0
SummaryTables = finBL.CreateSummaryTables()

For Each AccountClient In di.Account.Clients
  If AccountClient.AccountSignatory Then
  	' Increment Signature Counter
  	Count += 1

  	' Create Summary Table
  	SummaryTable = finBL.CreateSummaryTable()
  	With SummaryTable
  	  .TableClass = iseSummaryTableClass.TabularData
  	  .AutoStripe = False
  	  .WidthHtml = "100%"

  	  ' Add gap between Tables
  	  If Count <> 1 Then .TextBefore = vbNewLine

  	  ' Define Columns
      With .Columns
    		.AddText()
    		.AddText()
  	  End With

  	  ' Find Email Address
  	  Email = AccountClient.Client.ContactMethods.GetCurrentEmail().Value

  	  If Len(Email) = 0 Then
        ' No Email, so add normal signing block
    		With .Rows.Add.Cells()
    		  If di.Account.Clients.CountOwners = 1 Then
      			.AddWiki(String.Format("**Signed as {0}**", AccountClient.AccountRoleDescriptionResolved) & vbNewLine & vbNewLine)
    		  Else
      			.AddWiki(String.Format("**Signed as {0} {1}**", AccountClient.AccountRoleDescriptionResolved, Count) & vbNewLine & vbNewLine)
    		  End If
      		  .AddWiki("--Witness Signature--")
    		End With
    		With .Rows.Add.Cells()
    		  .AddWiki(String.Format("--**{0}**{1}--", AccountClient.Client.AddresseeNameResolved2 & vbNewLine, AccountClient.Client.ContactAddresses.GetAddressForLetters(False)))
    		  .AddWiki("--Witness Name and Address--" & vbNewLine & vbNewLine & vbNewLine)
    		End With
  	  Else
        ' Find Secured Signing SmartTag
  			With AccountClient.Client
  			  ESignatureSmartTag = String.Format("[!Sign.{0}.F,{1},{2},{3}]", Count, Replace(.FirstName, ",", ""), Replace(.LastName, ",", ""), Email)
        end with
        
        ' Make Signature Small so it fits better
        ESignatureSmartTag = "--" & ESignatureSmartTag & "--"
        
        ' Pad top with New Lines as Signature Block is aligned bottom/ left
        ESignatureSmartTag = vbNewLine & vbNewLine & vbNewLine & vbNewLine & vbNewLine & vbNewLine & ESignatureSmartTag

    		With .Rows.Add.Cells()
    		  If di.Account.Clients.CountOwners = 1 Then
      			.AddWiki(String.Format("**Signed as {0}**", AccountClient.AccountRoleDescriptionResolved) & ESignatureSmartTag)
    		  Else
      			.AddWiki(String.Format("**Signed as {0} {1}**", AccountClient.AccountRoleDescriptionResolved, Count) & ESignatureSmartTag)
    		  End If
          .AddWiki(String.Format("--**{0}**{1}--", AccountClient.Client.AddresseeNameResolved2 & vbNewLine, AccountClient.Client.ContactAddresses.GetAddressForLetters(False)))
    		End With
  	  End If
  	End With

  	SummaryTables.Add(String.Format("Signature.{0}", Count), SummaryTable)
  End If
Next

wordDocumentBookmarks.SetContentSummaryTables("BookmarkName", SummaryTables)
