Journal Entry Event handler not getting applied to excel upload

Upkar
New Contributor II

Hi All!, 

My team and I have placed a JE event handler with restrictions for preparer and approver (where preparer can't approve his/her own JEs - Approve/reject/post & Unpost) along with JE email notification.

In this Scenario where a user has both Preparer and Approver access, submits JE through excel, his/her JE is getting directly approved without considering the restrictions we have placed in the JE event handler but when done manually it's working as expected. below is our BR. any help will be greatly appreciated. 

 

Public Function Main(ByVal si As SessionInfo, ByVal globals As BRGlobals, ByVal api As Object, ByVal args As JournalsEventHandlerArgs) As Object
Try
	Dim returnValue As Object = args.DefaultReturnValue
	args.UseReturnValueFromBusinessRule = False
	args.Cancel = False

	'Evaluate the operation type in order to determine which subroutine to process
							
	Select Case args.OperationName
				
	'SUBMITTED - Notifiy Approver
	Case Is = BREventOperationType.Journals.SubmitJournal
		If(args.isBeforeEvent)
			'' MG
			Dim isAdmin As Boolean = BRApi.Security.Authorization.IsUserInAdminGroup(si)
			Dim wfName = BRApi.Workflow.Metadata.GetProfile(si, si.WorkflowClusterPk).Name
			Dim journal As JournalEx = DirectCast(args.Inputs(1), JournalEx)
			Dim cubeName As String = GetCubeFromJournal(si, journal)
			brapi.ErrorLog.LogMessage(si, "CreateduserId: " & journal.Header.Header.CreatedUserID.ToString) 
			brapi.ErrorLog.LogMessage(si, "UserId: " & si.AuthToken.UserUniqueID.ToString)
			If cubename = "CCR" And journal.Header.Header.CreatedUserID = si.AuthToken.UserUniqueID Then
				If Not isAdmin Then
					If Not wfName.Contains("Corp") 
						Dim userinfo As UserInfo = BRApi.Security.Authorization.GetUser(si, si.UserName)
						Dim groups As New List(Of String)
						'' Groups assosciated with this user
						For Each userGrp As Group In userinfo.ParentGroups.Values
							groups.Add(userGrp.Name)
						Next
						Dim wfParent As String = BRApi.Workflow.Metadata.GetParent(si, si.WorkflowClusterPk.ProfileKey).Name
						Dim isInLEGroup As Boolean = groups.Any(Function(x) x.Contains(wfParent & "_Preparer"))
						'brapi.ErrorLog.LogMessage(si, "WfParent: " & wfparent & " - " & isInLEGroup)
						If isInLEGroup Then
							Me.XFR_HandleFinalizeSubmitJournal(si, globals, api, args)
						Else
							Throw New XFException("Security Access Error: Only preparer can create and submit journal for the current Workflow")
						End If
					End If
				End If
			End If
		End If
	Case Is = BREventOperationType.Journals.FinalizeSubmitJournal
		If(args.isBeforeEvent)
			'' MG
			Dim isAdmin As Boolean = BRApi.Security.Authorization.IsUserInAdminGroup(si)
			Dim wfName = BRApi.Workflow.Metadata.GetProfile(si, si.WorkflowClusterPk).Name
			Dim journal As JournalEx = DirectCast(args.Inputs(1), JournalEx)
			Dim cubeName As String = GetCubeFromJournal(si, journal)
			brapi.ErrorLog.LogMessage(si, "CreateduserId: " & journal.Header.Header.CreatedUserID.ToString) 
			brapi.ErrorLog.LogMessage(si, "UserId: " & si.AuthToken.UserUniqueID.ToString)
			If cubename = "CCR" And journal.Header.Header.CreatedUserID = si.AuthToken.UserUniqueID Then
				If Not isAdmin Then
					If Not wfName.Contains("Corp")
						Dim userinfo As UserInfo = BRApi.Security.Authorization.GetUser(si, si.UserName)
						Dim groups As New List(Of String)
						'' Groups assosciated with this user
						For Each userGrp As Group In userinfo.ParentGroups.Values
							groups.Add(userGrp.Name)
						Next
						Dim wfParent As String = BRApi.Workflow.Metadata.GetParent(si, si.WorkflowClusterPk.ProfileKey).Name
						Dim isInLEGroup As Boolean = groups.Any(Function(x) x.Contains(wfParent & "_Preparer"))
						'brapi.ErrorLog.LogMessage(si, "WfParent: " & wfparent & " - " & isInLEGroup)
						If isInLEGroup Then
							Me.XFR_HandleFinalizeSubmitJournal(si, globals, api, args)
						Else
							Throw New XFException("Security Access Error: Only preparer can create and submit journal for the current Workflow")
						End If
					End If
				End If
			End If
		End If
	
	Case Is = BREventOperationType.Journals.ApproveJournal
		If(args.isBeforeEvent)
			Dim journal As JournalEx = DirectCast(args.Inputs(1), JournalEx)
			Dim cubeName As String = GetCubeFromJournal(si, journal)
			brapi.ErrorLog.LogMessage(si, "CreateduserId: " & journal.Header.Header.CreatedUserID.ToString)
			brapi.ErrorLog.LogMessage(si, "UserId: " & si.AuthToken.UserUniqueID.ToString)
			If cubename = "CCR" And journal.Header.Header.CreatedUserID = si.AuthToken.UserUniqueID Then
				brapi.ErrorLog.LogMessage(si, "God let it work:approveJournal ")
				Throw New XFException("Journal can't be approved by the same user as the creator")
			End If
		End If
				
	'APPROVED - Notify Submitter
	Case Is =  BREventOperationType.Journals.FinalizeApproveJournal
		If(args.isBeforeEvent)
			Dim journal As JournalEx = DirectCast(args.Inputs(1), JournalEx)
			Dim cubeName As String = GetCubeFromJournal(si, journal)
			brapi.ErrorLog.LogMessage(si, "CreateduserId: " & journal.Header.Header.CreatedUserID.ToString)
			brapi.ErrorLog.LogMessage(si, "UserId: " & si.AuthToken.UserUniqueID.ToString)
			If cubename = "CCR" And journal.Header.Header.CreatedUserID = si.AuthToken.UserUniqueID Then
				brapi.ErrorLog.LogMessage(si, "God let it work:finalizejournaL ")
				Throw New XFException("Journal can't be approved by the same user as the creator")
			End If
		Else 
			Me.XFR_HandleFinalizeApproveJournal(si, globals, api, args)
		End If
	
	'POST - Notify Submitter
	Case Is = BREventOperationType.Journals.PostJournal
		If(args.isBeforeEvent) 
			Dim journal As JournalEx = DirectCast(args.Inputs(1), JournalEx)
			Dim cubeName As String = GetCubeFromJournal(si, journal)
			If cubename = "CCR" And journal.Header.Header.CreatedUserID = si.AuthToken.UserUniqueID Then
				Throw New XFException("Journal can't be posted by the same user as the creator")
			End If
		End If

	Case Is = BREventOperationType.Journals.FinalizePostJournal
		If(args.isBeforeEvent) 
			Dim journal As JournalEx = DirectCast(args.Inputs(1), JournalEx)
			Dim cubeName As String = GetCubeFromJournal(si, journal)
			If cubename = "CCR" And journal.Header.Header.CreatedUserID = si.AuthToken.UserUniqueID Then
				Throw New XFException("Journal can't be posted by the same user as the creator")
			End If
		End If
		
	'REJECTED - Notify Submitter
	Case Is = BREventOperationType.Journals.RejectJournal
		If(args.isBeforeEvent) 
			Dim journal As JournalEx = DirectCast(args.Inputs(1), JournalEx)
			Dim cubeName As String = GetCubeFromJournal(si, journal)
			brapi.ErrorLog.LogMessage(si, "CreateduserId: " & journal.Header.Header.CreatedUserID.ToString)
			If cubename = "CCR" And journal.Header.Header.CreatedUserID = si.AuthToken.UserUniqueID Then
						Throw New XFException("Journal can't be rejected by the same user as the creator.")
			End If
		End If

	Case Is = BREventOperationType.Journals.FinalizeRejectJournal
		If(args.isBeforeEvent) 
			Dim journal As JournalEx = DirectCast(args.Inputs(1), JournalEx)
				Dim cubeName As String = GetCubeFromJournal(si, journal)
				brapi.ErrorLog.LogMessage(si, "CreateduserId: " & journal.Header.Header.CreatedUserID.ToString)
			If cubename = "CCR" And journal.Header.Header.CreatedUserID = si.AuthToken.UserUniqueID Then
				Throw New XFException("Journal can't be rejected by the same user as the creator.")
			End If
		Else
			Me.XFR_HandleFinalizeRejectJournal(si, globals, api, args)                                                                
		End If 
		
	' UNPOST
	Case Is = BREventOperationType.Journals.UnpostJournal
		If(args.isBeforeEvent = True) 
			Dim journal As JournalEx = DirectCast(args.Inputs(1), JournalEx)
			Dim cubeName As String = GetCubeFromJournal(si, journal)
			If cubename = "CCR" And journal.Header.Header.CreatedUserID = si.AuthToken.UserUniqueID Then
				Throw New XFException("Journal can't be un-posted by the same user as the creator.")
			End If
		End If 
				
	Case Is = BREventOperationType.Journals.FinalizeUnpostJournal
		If(args.isBeforeEvent = True) 
			Dim journal As JournalEx = DirectCast(args.Inputs(1), JournalEx)
			  Dim cubeName As String = GetCubeFromJournal(si, journal)
			If cubename = "CCR" And  journal.Header.Header.CreatedUserID = si.AuthToken.UserUniqueID Then
						Throw New XFException("Journal can't be un-posted by the same user as the creator.")
			End If
		End If 
				
	Case Is = BREventOperationType.Journals.StartUpdateJournalWorkflow
		Dim cubeName = brapi.Workflow.Metadata.GetProfile(si, si.WorkflowClusterPk).CubeName
		If (cubeName = "CCR") Then
		   If Not BRApi.Security.Authorization.IsUserInGroup(si, "WF_CCR_All_Approver")  Then
			' Do nothing

		   Else
			   If BRApi.Security.Authorization.IsUserInGroup(si, "WF_CCR_All_Approver") And Not BRApi.Security.Authorization.IsUserInGroup(si, "Administrators") And Not BRApi.Security.Authorization.IsUserInGroup(si, "WF_CCR_All_Preparer") Then
				 If (args.IsBeforeEvent=False) Then								
					 Throw (New XFUserMsgException(si, Nothing, Nothing, "Security Access Error. Only preparer can execute the current workflow step."))
				 End If
			   End If
		   End If
		End If																		

	End Select
				
	Return returnValue
	
Catch ex As Exception
	Throw ErrorHandler.LogWrite(si, New XFException(si, ex))
End Try
' End Function

 

1 REPLY 1

ChrisLoran
Valued Contributor

Hello Upkar,
What version of OneStream are you using?
I presume you are referring to a JournalsEventHandler?

Have you tried putting in LogMessage statements to prove whether the JournalsEventHandler genuinely does/does not execute at all when uploading from Excel?  Could you state what you see in the error log after repeating the tests, after you put a LogMessage statement right at the top of the JournalsEventHandler.

Also , what do you mean by "doing it manually"?  Do you mean that if you upload a journal from Excel and then press the Approve/Submit buttons in the toolbar on the OneStream client, then the eventhandler does trigger.  Could you show the steps you are doing on how to reproduce the issue of the EventHandler not triggering, because it is not clear from the above, in particular the attempt to "submit through Excel".

Contributors on this forum might be able assess the issue and confirm whether it is/is not something that can be resolved or workarounds, but I suspect this may be something that should be raised as a ticket with support, as this is querying some design considerations/design decisions deep inside the platform, and you are unlikely to get a line through to product engineering on this forum.