| 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 finAccountLogDim Ok As Boolean' Assume SuccessOk = True' Create Log and Generate MessageAccountLog = finBL.CreateAccountLog()With AccountLog.LogType = isefinLogType.DocumentEmail ' Makes the Log publishable.AccountId = "L10000".DocumentId = "AAEmail".Subject = "Test Message"' Generate MessageOk = .GenerateMessageEmail(True, "x@sendtoemailaddress")' SaveIf 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 OnOption Strict OnPublic 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 SuccessMain = True' Handle EventsSelect Case eventIdCase "GenerateMessage"' Generate and return Message and SubjectreturnValues.SetString("message", "Message from Script for Account " & DirectCast(source, finAccount).AccountId)returnValues.SetString("subject", "Subject from Script")' Always CC this email addressreturnValues.SetString("cc", "123@intersoft.co.nz")End SelectEnd 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 OnOption Strict OnPublic 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 BooleanDim DocumentId As StringDim LogPublishBatch As finLogPublishBatchDim LogPublishBatchItem As finLogPublishBatchItemDim strTemp As StringDim TemplateDocument As String' Assume SuccessMain = True' InitialiseLogPublishBatch = DirectCast(source, finLogPublishBatch)' Handle EventsSelect Case eventIdCase "Publish"' InitialiseDocumentId = DirectCast(parameters, ISKeyValueList).GetString("DocumentId")TemplateDocument = finBL.Documents(DocumentId).TemplateDocumentFor Each LogPublishBatchItem In LogPublishBatchWith 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 = strTempElse.PublishSuccess = FalseEnd IfEnd WithNextEnd SelectEnd 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.