<?xml version="1.0" encoding="utf-8"?><finScript version="1.00" exportedUtcDate="2017-02-12T19:53:27.0000000"><CreatedUserId>Admin</CreatedUserId><CreatedUtcDate>2017-01-17T03:49:43.6610000</CreatedUtcDate><UpdatedUserId>Admin</UpdatedUserId><UpdatedUtcDate>2017-02-12T19:50:29.3350000</UpdatedUtcDate><ScriptId>SL.CLIENTS</ScriptId><Description>Clients Smart List Tutorial</Description><ScriptType>SmartList</ScriptType><Active>true</Active><AllowUI>false</AllowUI><Category /><Code>Option Explicit On
Option Strict On

' #################################################################
' Short Script Description
'
' Version: 1.00 (13/02/2017)
'
' Usage: Location that this Script is used
' #################################################################

' Objects
Private mEventArgs As ISKeyValueList
Private mSmartListHandler As finSmartListHandler

Public Function Main(smartListHandler As finSmartListHandler, eventId As String, eventArgs As ISKeyValueList, hostingContext As isefinSmartListHostingContext, scriptRequestInfo As finScriptRequestInfo) As Boolean

  ' Assume Success
  Main = True

  ' Initialise
  mEventArgs = eventArgs
  mSmartListHandler = smartListHandler

  ' Handle Events
  Select Case eventId
    Case "Initialise"
      ' Initialise
      Main = Initialise()

    Case "Execute"
      ' Execute
      Main = Execute()

    Case "GetRowSummary"
      ' Get Row Summary
      GetRowSummary()

    Case "ExecuteRowAction"
      ' Execute Row Action
      Main = ExecuteRowAction()
  End Select

End Function

Private Function Execute() As Boolean

  Dim CitiesRange As String
  Dim dt As DataTable
  Dim Parameters As ISKeyValueList
  Dim sqb As ISSelectQueryBuilder
  Dim sqbCities As ISSelectQueryBuilder
  Dim Success As Boolean

  ' Assume Success
  Success = True

  ' Initialise
  Parameters = mSmartListHandler.ExecutionParameters
  sqb = finBL.Database.CreateSelectQueryBuilder()
  sqbCities = finBL.Database.CreateSelectQueryBuilder()

  ' Get Parameters
  With Parameters
    CitiesRange = .GetString("CitiesRange")
  End With

  ' Create Query
  With sqb
    .Table = "Client"
    .Fields.AddList("Pk,ClientId,Name,DateOfBirth,Status")

    ' SQL Where
    With .SqlWhere
      If Len(CitiesRange) = 0 Then
        ' Return no records if not filtered
        .AppendComparisonInteger("Pk", "=", -1)
      Else
        ' Cities (include Suburb)
        With sqbCities
          .Table = "ClientContactAddress"
          .Fields.Add("ClientPk")

          With .SqlWhere
            .AppendComparisonField("ClientContactAddress.ClientPk", "=", "Client.Pk")

            ' City/ Suburb
            .BlockBegin(iseSqlWhereBuilderNestedBlockType.OrBlock)
            .AppendRange("City", CitiesRange)
            .AppendRange("Suburb", CitiesRange)
            .BlockEnd()

            ' Current Addresses Only
            .AppendComparisonIntegerBoolean("Historic", "=", False)
            .BlockBegin(iseSqlWhereBuilderNestedBlockType.OrBlock)
            .AppendComparisonNull("DateStop")
            .AppendComparisonDate("DateStop", "&lt;", finBL.TimeZoneFunctions.GetCurrentDatabaseDate().AddDays(1), False)
            .BlockEnd()
          End With
        End With

        .AppendInSubQuery("Pk", sqbCities)
      End If

      ' User Filters
      .Append(finBL.CurrentUserInformation.FilterClientSqlWhere)
    End With

    ' Order By
    .OrderByFields.Add("ClientId")
  End With

  ' Execute
  Success = sqb.ExecuteDataTable(dt)

  ' Set Smart List Results
  If Success Then
    mSmartListHandler.Results.DataSetFromDataTable(dt)
  End If

  ' Displaying a Summary?
  mSmartListHandler.SupportsSummary = Parameters.GetBoolean("ShowSummary")

  Return Success

End Function

Private Function Initialise() As Boolean

  Dim Success As Boolean

  ' Assume Success
  Success = True

  ' Define Columns
  With mSmartListHandler.Columns
    .AddClientStatus("Status")
    .AddCode("ClientId", "Code",,,"Clients").AlwaysInclude = True
    .AddString("Name", "Name")
    .AddDate("DateOfBirth", "DOB")

    ' Hidden (will always be included in results)
    .AddHidden("Pk")
  End With

  ' Summary Support
  mSmartListHandler.SupportsSummary = True
  mSmartListHandler.SummaryColumns = "Pk"

  ' Define Actions
  With mSmartListHandler.Actions
    .AddRowFormOpen("SendEmail", "EmailMessage", "ClientId", "type=Client&amp;subject=Test Email from Smart List", "Email", "", "Open the Send Email Message wizard")
    .AddRowCustom("RequestAddressUpdate", True, True, True, "", "Email", "Confirm Address", "Send an Email for Client to confirm their Address details")
  End With

  Return Success

End Function

Private Sub GetRowSummary()

  Dim Pk As Integer
  Dim SummaryColumns As ISKeyValueList

  ' Get Event Args
  SummaryColumns = mEventArgs.GetKeyValueList("SummaryColumns")

  ' Get Summary Column Values that uniquely identify a record
  Pk = SummaryColumns.GetInteger("Pk")

  ' Get HTML
  mSmartListHandler.RowSummary = finBL.SummaryPageFunctions.ClientSummary(False, Pk, Nothing, ScriptInfo.Target)

End Sub

Private Function ExecuteRowAction() As Boolean

  Dim Action As finSmartListAction
  Dim ActionId As String
  Dim Parameters As ISKeyValueList
  Dim Success As Boolean
  Dim SummaryColumns As ISKeyValueList
  Dim Pk As Integer

  ' Assume Success
  Success = True

  ' Get Event Args
  With mEventArgs
    ActionId = .GetString("ActionId")
    Parameters = .GetKeyValueList("Parameters")
    SummaryColumns = mEventArgs.GetKeyValueList("SummaryColumns")
  End With

  ' Get Summary Column Values that uniquely identify a record
  Pk = SummaryColumns.GetInteger("Pk")

  ' Get Action
  If mSmartListHandler.Actions.Exists(ActionId) Then
    Action = mSmartListHandler.Actions(ActionId)
  Else
    Success = False
    finBL.Error.ErrorBeginFormat("Action '{0}' not found.", ActionId)
  End If

  ' Execute Action
  If Success Then
    Select Case Action.ActionId
      Case "RequestAddressUpdate"
        Success = ExecuteRowAction_RequestAddressUpdate(Pk)

      Case Else
        Success = False
        finBL.Error.ErrorBeginFormat("Action '{0}' not handled.", Action.ActionId)
    End Select
  End If

  Return Success

End Function

Private Function ExecuteRowAction_RequestAddressUpdate(clientPk As Integer) As Boolean

  Dim Client As finClient
  Dim CurrentAddress As ISAddressDetails
  Dim EmailAddress As String
  Dim Message As String
  Dim Recipients As finMessageRecipients
  Dim sb As StringBuilder
  Dim Subject As String
  Dim Success As Boolean

  ' Assume Success
  Success = True

  ' Load Client
  Client = finBL.CreateClient()
  Success = Client.LoadPk(clientPk)

  ' Locate current Email
  If Success Then
    EmailAddress = Client.ContactMethods.GetCurrentEmail().Value

    ' Validate
    If len(EmailAddress) = 0 Then
      Success = False
      finBL.Error.ErrorBegin("Client does not have a current Email address.")
    End If
  End If

  ' Locate current Physical Address
  If Success Then
    CurrentAddress = Client.ContactAddresses.GetCurrentPostalAddress()
  End If

  ' Build Email message
  If Success Then
    Subject = "Address Confirmation"

    sb = New StringBuilder()
    With sb
      .AppendLine(String.Format("Dear {0}", Client.SalutationResolved))
      .AppendLine()
      If CurrentAddress.HasValue Then
        .AppendLine("We have the following postal address recorded for you:")
        .AppendLine()
        .AppendLine(finBL.Addressing.FormatAddressFromAddressDetails(CurrentAddress))
        .AppendLine()
        .AppendLine("If your address has changed, please could you email your new address details so we can update our records.")
      Else
        .AppendLine("We do not have a current postal address recorded for you.")
        .AppendLine("Please could you email your address details so we can update our records.")
      End If

      .AppendLine()
      .AppendLine("Regards,")
      .AppendLine()
      .AppendLine(finBL.CurrentUserInformation.UserName)
    End With

    Message = sb.ToString()
  End If

  ' Send Email
  ' NOTE: This also generates a Client Log
  If Success Then
    Recipients = finBL.CreateMessageRecipients()
    With Recipients
      ' Initialise
      .AddClient(Client.ClientId, Client.Name, EmailAddress)
      .GenerateMessages(Message, finBL.TimeZoneFunctions.GetCurrentDatabaseDate(), Subject)

      ' Send (append signature and use standard HTML Email template)
      Success = .SendEmail(iseMessageTarget.Send, Nothing, True, "", "*", "*")
    End With
  End If

  ' Do not expire row
  mSmartListHandler.ResultsRowAction.Expired = False

  Return Success

End Function</Code><Language>VisualBasic</Language><Notes>Smart List created from the tutorial in the HTML Widgets document.</Notes><PermissionKeyExecute /><RunWithoutPrompts>false</RunWithoutPrompts><TemplateText /><TimeoutSeconds>60</TimeoutSeconds><AllowRefresh>true</AllowRefresh><Caption /><WebServiceName /><WebServiceSendDebugInformation>false</WebServiceSendDebugInformation><ParametersType>Custom</ParametersType><Parameters><ISParameterDefs version="1.00"><Parameters><Parameter name="" type="SectionStart"><BlankTip /><Caption>Display options.</Caption><StandaloneOnly>false</StandaloneOnly><TooltipText /><SectionColumns>1</SectionColumns><Visible>true</Visible></Parameter><Parameter name="ShowSummary" type="Boolean"><BlankTip /><Caption>Show a Summary for the selected row?</Caption><StandaloneOnly>false</StandaloneOnly><TooltipText /><DefaultValueExpression /><Enabled>true</Enabled><HideDescription>false</HideDescription><IndentLevel>0</IndentLevel><NonPersistable>false</NonPersistable><ReadOnly>false</ReadOnly><ReadOnly2>false</ReadOnly2><Value>True</Value><Visible>true</Visible></Parameter><Parameter name="" type="SectionStart"><BlankTip /><Caption>Specify any Range filters you require.</Caption><StandaloneOnly>false</StandaloneOnly><TooltipText /><SectionColumns>1</SectionColumns><Visible>true</Visible></Parameter><Parameter name="CitiesRange" type="Text"><BlankTip /><Caption>Cities</Caption><StandaloneOnly>false</StandaloneOnly><TooltipText /><DefaultValueExpression /><Enabled>true</Enabled><HideDescription>false</HideDescription><IndentLevel>0</IndentLevel><Mandatory>false</Mandatory><NonPersistable>false</NonPersistable><ReadOnly>false</ReadOnly><ReadOnly2>false</ReadOnly2><Value /><Visible>true</Visible><MaxLength>0</MaxLength><Rows>1</Rows></Parameter></Parameters></ISParameterDefs></Parameters></finScript>