Article Details
Id:12296
Product:finPOWER Connect
Type:NEW
Version:2.02.01
Opened:30/09/2014
Closed:06/10/2014
Released:14/10/2014
Job: J014204

Documents; "GenerateMessage" Script event can now be called when creating a Log from the business layer

Previously, the "GenerateMessage" event of a Document was only called from the User Interface when creating a Document.

Both the finAccountLog and finClientLog business layer objects now have the following methods which allow a Document's message to be recorded against the Log from the business layer:

  • GenerateMessageEmail
  • GenerateMessageSms

Each of these methods updates the appropriate properties on the Log, e.g., the ExtendedType and ExtendedData properties.

The following code sample creates an Account Log and generates messages from the specified Document. This assumes that the Document has either a Template Message and Subject configured or generates these via the "GenerateMessage" Script event:

Dim AccountLog As finAccountLog
Dim Ok As Boolean

' Assume Success
Ok = True

' Create Log and Generate Message
AccountLog = finBL.CreateAccountLog()
With AccountLog
  .LogType = isefinLogType.DocumentEmail ' Makes the Log publishable
  .AccountId = "L10000"
  .DocumentId = "AAEmail"
  .Subject = "Test Message"

  ' Generate Message
  Ok = .GenerateMessageEmail(True, "x@sendtoemailaddress")

  ' Save
  If Ok Then Ok = .Save()
End With

The following code sample is for a Document's Script and generates a message and subject and also specifies who to CC to (so the emailCc parameter could be omitted in the above example):

Option Explicit On
Option Strict On

Public Function Main(source As Object, eventId As String, eventArgs As ISKeyValueList, ByRef handled As Boolean, parameters As Object, ByRef returnValues As ISKeyValueList, ByRef text As String) As Boolean

  ' Assume Success
  Main = True

  ' Handle Events
  Select Case eventId
    Case "GenerateMessage"
      ' Generate and return Message and Subject
      returnValues.SetString("message", "Message from Script for Account " & DirectCast(source, finAccount).AccountId)
      returnValues.SetString("subject", "Subject from Script")
      
      ' Always CC this email address
      returnValues.SetString("cc", "123@intersoft.co.nz")
  End Select

End Function

For HTML Documents, the Document Publish process will take care of generating the HTML providing the Document's Script code is written to correctly handle the "Publish" event. An example is given below (this sample is given for completeness, even though it is not related to the new functionality) :

Option Explicit On
Option Strict On

Public Function Main(source As Object, eventId As String, eventArgs As ISKeyValueList, ByRef handled As Boolean, parameters As Object, ByRef returnValues As ISKeyValueList, ByRef text As String) As Boolean
  
  Dim DocumentId As String
  Dim LogPublishBatch As finLogPublishBatch  
  Dim LogPublishBatchItem As finLogPublishBatchItem
  Dim strTemp As String
  Dim TemplateDocument As String

  ' Assume Success
  Main = True
  
  ' Initialise
  LogPublishBatch = DirectCast(source, finLogPublishBatch)

  ' Handle Events
  Select Case eventId
    Case "Publish"
      ' Initialise
      DocumentId = DirectCast(parameters, ISKeyValueList).GetString("DocumentId")
      TemplateDocument = finBL.Documents(DocumentId).TemplateDocument 
      
      For Each LogPublishBatchItem In LogPublishBatch
        With LogPublishBatchItem 
          ' Just replace Tags in Template Document (Id property is an Account Id)
          If finBL.DocumentFunctions.ResolveTaggedMessageHtml(TemplateDocument, .LogDate, strTemp, .Id) Then
            .PublishSuccess = True
            .PublishDocumentHtml = strTemp
          Else
            .PublishSuccess = False
          End If
        End With
      Next
  End Select

End Function

NOTE: Currently (as at version 2.02.01 of finPOWER Connect), the publish is acutally handled via the User Interface, therefore, if publishing this Log directly from the business layer, this may not produce the expected results.