Forum Discussion

ssmith-nova's avatar
ssmith-nova
New Contributor III
12 days ago
Solved

Execute a Workflow multiple times with different periods from a BR

I am trying to automate a yearly load of data from a business rule.  I want the rule to loop through a set of periods and run a specific workflow for that period.  The workflow uses a connector rule in which I get the scenario and period of the workflow being run.  

THe issue I am facing is that I can get the WorkflowPK for the workflow/scenario/time that I want to run.  But when I call BRApi.Import.Process.ExecuteParseAndTransform with that key, a workflow starts, but if I happen to be on that workflow in the session I am running it picks up the POV from where I am at.  So if I want my business rule to run 3 periods (Jan - Mar).  If I am on Dec, then it runs December every time.  Below us how I get the WFPK and call the 

Dim wfClusterPk As WorkflowUnitClusterPk = BRApi.Workflow.General.GetWorkflowUnitClusterPk(si, wfProfileInfo.Name, wfScenarioName, wfTimeName) 
'---------------------------------
'   Parse and Transform:
'---------------------------------
Dim ImportInfo As New LoadTransformProcessInfo 
ImportInfo  = BRApi.Import.Process.ExecuteParseAndTransform(si, wfClusterPk, String.Empty, Nothing, TransformLoadMethodTypes.Replace, SourceDataOriginTypes.FromDirectConnection, False)

Here is my connector rule that gets the scenario and the time;

Dim wfPk As WorkflowUnitPk = BRApi.Workflow.General.GetWorkflowUnitPk(si)
Dim wfProfileInfo As WorkflowProfileInfo = BRApi.Workflow.Metadata.GetProfile(si, wfPK.ProfileKey)
'Get the WF Time and WF Scenario from API
wfTime = brapi.Finance.Members.GetMemberName(si, dimtypeid.Time, si.WorkflowClusterPk.TimeKey)
wfScenario = ScenarioDimHelper.GetNameFromID(si, wfPk.ScenarioKey)

Dim objTimeMemberSubComponents As TimeMemberSubComponents = BRApi.Finance.Time.GetSubComponentsFromName(si, wfTime)				
wfFiscalYr = objTimeMemberSubComponents.Year
wfFiscalPer = objTimeMemberSubComponents.Month

Any and all thoughts are appreciated.

Scott

  • Hi ssmith-nova 

    If you derive the WorkflowUnitClusterPk from the Transformer api in the connector rule (rather than deriving this from SessionInfo), this will enable you to control, the WFProfile, Scenario and Time in your logic, as desired

    Hope this helps

    Sam

  • sameburn's avatar
    sameburn
    Contributor III

    Hi ssmith-nova 

    If you derive the WorkflowUnitClusterPk from the Transformer api in the connector rule (rather than deriving this from SessionInfo), this will enable you to control, the WFProfile, Scenario and Time in your logic, as desired

    Hope this helps

    Sam

    • sameburn's avatar
      sameburn
      Contributor III

      The transformer api is only available from a Connector rule. Not sure I understand the question, since a Finance BR will serve a different use case entirely

  • ssmith-nova's avatar
    ssmith-nova
    New Contributor III

    In the Finance BR we are trying to get the timeId from the running WF.  We want to be able to process loads using HarvestBatch, but like above, when the automated job runs the Finance BR uses the session information not what is actually running.

  • sameburn's avatar
    sameburn
    Contributor III

    In this use case, you can control wf, Scenario and Time using the batch harvest file created. Instead of using Transformer api. This would be your control. Not sure where finance rules fit into this though

    • ssmith-nova's avatar
      ssmith-nova
      New Contributor III

      To your point here, if I have the scenario and time on the batch harvest files, when I run ExecuteFileHarvestBatch, does it ignore what I put for the scenario and time? Or is there a default at this level?  On the file you can include C or G for time for the current period or global period.   But I haven't seen anything for the ExecuteFileHarvestBatch command:

      Function IBRApiUtilities.ExecuteFileHarvestBatch(si As Sessioninfo, currentScenarioName As String, currentTimeName As String, validateTransformation As Boolean, validateIntersections As Boolean, loadCube As Boolean, processCube As Boolean, confirm As Boolean, autoCertify As Boolean, throwOnError As Boolean) As WorkflowBatchFileCollection

  • ssmith-nova's avatar
    ssmith-nova
    New Contributor III

    I got that part working.  The Finance rule is running as a calc during the Process step of the workflow.

  • sameburn's avatar
    sameburn
    Contributor III

    If you are controlling the scenario and Time (in terms of what you are executing via batch harvest), you should be able to persist these values for the rest of your logic?

    I recommend having a look at the batch harvest section in design & reference to demystify.

    Taking Scenario and Time from wfClusterPK will always default to where you are logged into in OnePlace (SessionInfo)

    Thanks

  • ssmith-nova's avatar
    ssmith-nova
    New Contributor III

    Hi Sam,

    Thank you for talking the time to reply to these questions.

    I am trying to load multiple time periods at once.  The WF that I am running is a direct connect so the file I am creating is empty. 

    I have two BRs, one is connector BR and one is an Extender BR.  In the Extender BR I am able to control the times that I want to run.  Typically, I would create a file and run the execute function.  Now I am trying to load six weeks of data (2025W1 - 2025W6).  I was trying to create six files, one for each week and then run the execute batch once. But the execute requires a time.  Is what I am trying to do not possible?

    It is in the Connector BR that I was having issue with the period.  But you solved that by telling me to get the time from the Transformer.  Now my issue is that the WF has a calculation attached to it.  It's when it gets into the calc that I need to get the time.  However, I think I resolved my issue by using api.Pov.Time.Name.  I am still testing.  

    Thanks again for your time,

    Scott