Final Message Preparation for Process without Parallelism*

This snippet should be put into epilog of the messaging enabled process to make sure the final message is properly formulated as a JSON string and global variables to pass messages to a calling process are set. The snippet is valid only for processes that are not parallel enabled and run in single thread mode and should be last code block in epilog tab of the process.

Note:

  • Messages are written into message cube by calling a process with RunProcess to isolate commit event of the message from commit event of the process. This might result in some time differences between the time when message is actually written and process result is indicated and the actual process finish.

  • nProcessReturn code is by definition set to 0 in case of process errors and non-zero otherwise!

Epilog:

#Region - Return code & final error message handling sProcessResultType = If( nErrors = 0, 'success', 'danger' ); If( nErrors > 0 ); sErrors = NumberToString( nErrors ); #Region - Failure Message Composition sProcessResultMsg = Expand( 'Process has finished with %sErrors% error' | If( nErrors > 1, 's', '') | '.' ); #EndRegion - Failure Message Composition If( nMultiMsgJSON <= 1 ); sProcessResultJSON = Expand( '{"process":"%cThisProcName%", "header": "%sProcessResultMsg%", "message":"%sMessage%", "type":"%sProcessResultType%"}' ); Else; sProcessResultJSON = Expand( '{"process":"%cThisProcName%", "header": "%sProcessResultMsg%", "details":{%sMultiMsg%}, "type":"%sProcessResultType%"}' ); EndIf; sMessage = sProcessResultMsg; nProcessReturnCode = 0; sProcessReturnCode = sProcessResultJSON; RunProcess( '}APQ.Cub.ProcessResponseMessage.ImmediateLog', 'pProcLogParams', sProcLogParams, 'pProcessStartTime', TimSt(nProcessStartTime, '\Y-\m-\d \h:\i:\s'), 'pProcessFinishTime', 'now', 'pUserName', cUserName, 'pProcessName', cThisProcName, 'pProcessErrorFile', GetProcessErrorFileName(), 'pStatus', 'Error', 'pSuccessMessage', '', 'pFailureMessage', sProcessResultMsg, 'pJSONMessage', sProcessReturnCode ); LogOutput( cMsgErrorLevel, Expand( cMsgErrorContent ) ); ProcessQuit(); Else; #Region - Success Message Composition sProcessResultMsg = 'Process has finished successfully.'; #EndRegion - Success Message Composition If( nMultiMsgJSON <= 1 ); sProcessResultJSON = Expand( '{"process":"%cThisProcName%", "header": "%sProcessResultMsg%", "message":"%sMessage%", "type":"%sProcessResultType%"}' ); Else; sProcessResultJSON = Expand( '{"process":"%cThisProcName%", "header": "%sProcessResultMsg%", "message":"%sMessage%", "details":{%sMultiMsg%}, "type":"%sProcessResultType%"}' ); EndIf; nProcessReturnCode = 1; sProcessReturnCode = sProcessResultJSON; RunProcess( '}APQ.Cub.ProcessResponseMessage.ImmediateLog', 'pProcLogParams', sProcLogParams, 'pProcessStartTime', TimSt(nProcessStartTime, '\Y-\m-\d \h:\i:\s'), 'pProcessFinishTime', 'now', 'pUserName', cUserName, 'pProcessName', cThisProcName, 'pProcessErrorFile', GetProcessErrorFileName(), 'pStatus', 'Success', 'pSuccessMessage', sProcessResultMsg, 'pFailureMessage', '', 'pJSONMessage', sProcessReturnCode ); LogOutput('INFO', Expand( 'Process:%cThisProcName%: %sMessage%' ) ); EndIf; #EndRegion - Return code & final error message handling

Â