Customizating Integration Manager Logs - Part 2

In my previous post I talked about all the out of the box options for setting up Integration Manager ("IM") logs and frankly, the Trace level log is good for most users of IM users. However, when "good" is not good enough, it's necessary to resort to some of the objects and functions available as part of IM's scripting library.

Errors Collection object, Error object, and functions

Integration Manager provides the Errors Collection object which is nothing more than a collection or list of all the errors generated during an integration. The Errors Collection must be explicitly retrieved in order to work with the properties within the collection. To navigate the collection we need the Error object to get information about the specific error within the Errors Collection, for example, time of the error, the specific error text, and the type of severity (error or warning).

IM also provides a number of functions that allow a developer to write into the log file directly. These functions are: LogDetail, LogDocDetail, LogWarning, and LogDocWarning. Each of these functions is discussed in greater detail in Part 5 - Using VBScript, Chapter 22 - Functions of the Integration Manager User's Guide. The following example puts all these together:

After Document script
'
' Created by Mariano Gomez, MVP
' This code is licensed under the Creative Commons 
' Attribution-NonCommercial-ShareAlike 3.0 Generic license.
Const SEVERITY_MEDIUM 1000
Const SEVERITY_CRITICAL 2000

Dim imErrors ' reference the Errors Collection
Dim imError ' reference a specific error within the collection

Set imErrors = GetVariable("Errors")  
If imErrors.Count > 0 Then
 For i = 1 to imErrors.Count
  Set imError = imErrors.Item(i) ' get the error represented by the index
 
  'Check the severity level of the error
  if imError.Severity = GetVariable("SeverityWarning") then
   'We have hit a warning
   LogDocWarning imError.MessageText, "", SEVERITY_MEDIUM, "Customer Name", SourceFields(somequery.CustomerName)
  Else
  ' We hit a major issue, so now we really want to log all details details
   LogDocDetail imError.MessageText, "", SEVERITY_CRITICAL, "Customer Name", SourceFields(somequery.CustomerName)
  End If
 Next 'Continue if there's more than 1 error
End If
  

Note that you can add event logs from anywhere where scripting is allowed in IM. The above sample code is just a small example of how you could customize the logs further, with information that's meaningful to you and your users.

Hope you found this information useful.

Until next post!

MG.-
Mariano Gomez, MVP
Intelligent Partnerships, LLC
http://www.IntelligentPartnerships.com

Comments

Popular posts from this blog

Power Apps - Application Monitoring with Azure Application Insights

DBMS: 12 Microsoft Dynamics GP: 0 error when updating to Microsoft Dynamics GP 2013 R2

eConnect Integration Service for Microsoft Dynamics GP 2010