Forum Discussion

adoat's avatar
adoat
New Contributor III
3 years ago

Is it possible to prevent a force consolidation to run on locked period ?

Hi,   Without entering into the discussion of whether this is a best practice or not. During some HFM replacement, we have seen occasionally that request being raised. So, is it possible to p...
  • adoat's avatar
    3 years ago

    The Answer is Yes!

    And has been partially answered here and there.

    Thank you Christian for the nice posts I could find (see below for the links).

    So in order to do so, you will actually have to first cancel the force consolidated.

    Then by retrieving the period selected for the execution, you will be able to run through the entities and check wether they are locked or not.

    If not, you will be able then to impact the calc status of the ones that aren't locked.

    And eventually run a simple consolidation.

    Be aware, this would only work if you run a force consolidate from the right click or a process step.

     

    Hope this helps.

     

     

    Kind regards,

     

     

    Aymar

     

     

    Namespace OneStream.BusinessRule.WcfEventHandler.WcfEventHandler
    	Public Class MainClass
    Public Function Main(ByVal si As SessionInfo, ByVal globals As BRGlobals, ByVal api As Object, ByVal args As WcfEventHandlerArgs) As Object
    	Try
    		Dim returnValue As Object = args.DefaultReturnValue
    		args.UseReturnValueFromBusinessRule = True
    		args.Cancel = False
    
    		If args.IsBeforeEvent AndAlso args.WcfServiceType = WcfServiceType.Calculate AndAlso (args.OperationName="CalculateChartLogic" OrElse args.OperationName= "StartConsolidation" OrElse args.OperationName= "StartProcessCube") Then
    
    			'Retrieve variable to pick up if consolidation is forced
    			Dim povList As List(Of DataUnitPk) = args.inputs(1)
    			Dim timeName As String = brapi.Finance.Members.GetMemberName(si, dimtypeid.Time, povList(0).TimeId)
    			Dim isForced As Boolean = args.inputs(2)
    			Dim isLogged As Boolean = args.inputs(3)
    
    			If isForced Then
    				'If it is forced then we cancel the force consolidation
    				args.Cancel = True
    
    				Dim cubeName As String = brapi.Finance.Cubes.GetCubeInfo(si, povlist(0).CubeId).Cube.Name			
    				Dim scenarioName As String = BRApi.Finance.Members.GetMemberName(si, dimtypeid.Scenario, povList(0).ScenarioId)
    				Dim entityName As String = BRApi.Finance.Members.GetMemberName(si, dimtypeid.Entity, povList(0).EntityId)
    				Dim parentName As String = BRApi.Finance.Members.GetMemberName(si, dimtypeid.Entity, povList(0).ParentId)
    				Dim currentMonth As Integer = BRApi.Finance.Time.GetPeriodNumFromId(si,povList(0).TimeId)
    				
    				'We retrieve the dimension name to make the rule multi cube ready
    				Dim dimName As String = BRApi.Finance.Dim.GetDim(si, New DimPk(dimtypeid.Entity, BRApi.Finance.Members.GetDimIdFromMemberId(si, dimTypeId.Entity, povList(0).ParentId))).Name
    				Dim timeId As Integer = BRApi.Finance.Time.GetFirstPeriodInYear(si,povList(0).TimeId)
    				Dim lockedStatus As Boolean = False
    				'For every entity under the parent being consolidate
    				For Each entMember As Member In brapi.Finance.Members.GetBaseMembers(si, brapi.Finance.Dim.GetDimPk(si, dimName), povList(0).EntityId)
    					'For every periods before the periode selected for the force consolidate, starting with the first period of the year
    					For i = 1 To currentMonth
    					
    						
    						Dim wfUnitClusterPK As WorkflowUnitClusterPk = BRApi.Workflow.General.GetInputWorkflowUnitClusterPkForMembers(si, povList(0).CubeId, povList(0).EntityId, povList(0).ScenarioId, timeId)
    						lockedStatus = BRApi.Workflow.Status.GetWorkflowStatus(si, wfUnitClusterPK).Locked
    '						brapi.ErrorLog.LogMessage(si, $"{cubeName}, {entMember.Name}, {parentName}, Local, {scenarioName}, {timeId}")
    
    						'If the workflow is locked for this specific period
    						If Not lockedStatus Then 
    
    							'We impact the calcstatus
    							Brapi.Finance.Data.ImpactCalcStatus(si, cubeName, entMember.Name, parentName, "Local", scenarioName, BRApi.Finance.Time.GetNameFromId(si,timeId))
    
    '							Brapi.ErrorLog.LogMessage(si, "Locked Status = " & lockedStatus & $"{cubeName}, {entMember.Name}, {parentName}, Local, {scenarioName}, {timeName2}")
    						End If
    						
    						'Next period
    						timeId=BRApi.Finance.Time.GetNextPeriod(si,timeId,False)
    					Next
    				Next
    				
    			
    				Dim parameters As New Dictionary(Of String, String) From {  {"wfcCube", cubeName},
    	                                                                    {"wfcScenario", scenarioName},
    	                                                                    {"wfcTime", timeName},
    	                                                                    {"wfcEntity", entityName}}
    				'We trigger a normal consolidation that will run on all impacted entities	
    				brapi.Utilities.StartDataMgmtSequence(si, "BR_RunConsolidation", parameters)
    					
    			End If	
    
    		End If
    
    		Return returnValue
    	Catch ex As Exception
    		Throw ErrorHandler.LogWrite(si, New XFException(si, ex))
    	End Try
    End Function
    	End Class
    End Namespace

     

     

     

    The associated data management should look like this :

     

     

    Don't forget to create the associated literal parameter in a dashboard unit in order for this to work.

     

    Related resources :

    https://community.onestreamsoftware.com/t5/Internal-Consultants-PIE/Force-consolidate-only-runs-for-the-selected-period/m-p/2106#M33

    https://community.onestreamsoftware.com/t5/Internal-Consultants-PIE/Retrieving-the-isLocked-property-from-CellStatus-not-working/m-p/3762/thread-id/224#M227