Forum Discussion

Ando's avatar
Ando
New Contributor II
2 years ago

WorkFlow Event Handler that when workflow is locked kicks off stored Procedure

Im trying to create a workflow Event Handler that kicks off when lets say a period is locked April 2023 will then kick off a stored procedure that copies data from a table leveraging the wtk of the locked period.  

  • OS_Pizza's avatar
    OS_Pizza
    Contributor III

    AndoAssuming that you want to trigger a procedure as soon as you click on Lock Workflow

        1. Create a Workflow Event Handler that will trigger copy leveraging the wtk of the locked period.

     

    Namespace OneStream.BusinessRule.WorkflowEventHandler.WorkflowEventHandler
    	Public Class MainClass
    		Public Function Main(ByVal si As SessionInfo, ByVal globals As BRGlobals, ByVal api As Object, ByVal args As WorkflowEventHandlerArgs) As Object
    			Try
    				Dim returnValue As Object = args.DefaultReturnValue
    				args.UseReturnValueFromBusinessRule = False
    				args.Cancel = False
    				
    				Select Case args.OperationName
    				  Case Is = BREventOperationType.Workflow.WorkflowLock
    					  If args.isBeforeEvent = True Then
    						  Dim Mywf As WorkflowUnitClusterPk = DirectCast(args.Inputs(0), WorkflowUnitClusterPk)
    						  Dim timeName As String = brapi.Finance.Time.GetNameFromId(si, Mywf.TimeKey)
    					  	  CopyData(timeName)
    					  End If 
    				End Select 
    				  
    				Return returnValue
    			Catch ex As Exception
    				Throw ErrorHandler.LogWrite(si, New XFException(si, ex))
    			End Try
    		End Function
    	
    	Sub CopyData(timeName As String)
                  
    			'Write your SQL query to copy data according to the time value 
    	End Sub 	
    		
    		
    	End Class
    End Namespace

       

     

  • JackLacava's avatar
    JackLacava
    Honored Contributor

    ... and?

    This is fairly straightforward; if you could elaborate a bit on what difficulty you're encountering, I'm sure that someone would be able to help.