Forum Discussion

YanSavinsky's avatar
YanSavinsky
New Contributor III
2 years ago

How to loop through all Import steps within the node of the workflow hierarchy?

Within the Extender business rule used to integrate with our ERP system I would like to loop through all the "Import" steps  within a specific node of workflow hierarchy and to read the values of the "TextX" properties. I've heard that this is possible but have no idea where to start. Any guidance would be greatly appreciated.

 

Yan

  • db_pdx's avatar
    db_pdx
    2 years ago

    Yup! Makes total sense what you are striving for.  The generalized strategy would be:

    • Get your list of base Import profiles; either systematically (ideal) or from a manual list (simple/effective)
    • For each profile, get the TextX property and add to a list
    • Do your SFTP checks against the list

    If we just focus on the first two components it might look something like the below. For clarity I'll assume the following structure:

    Parent Level Workflow Group

    |---  Workflow1
             |----- Import
             |----- Forms
             |----- Adj
    
    |---  Workflow2
             |----- Import
             |----- Forms
             |----- Adj
    
    |--- Etc...

    Getting the list of .Import workflows (Workflow1.Import, Workflow2.Import):

    Dim parentWfProfileInfo As WorkflowProfileInfo = BRApi.Workflow.Metadata.GetProfile(si, _
        "Parent Level Workflow Group")
    Dim baseWfProfileInfo As New List (Of WorkflowProfileInfo)( _
        BRApi.Workflow.Metadata.GetRelatives(si, _
             BRApi.Workflow.General.GetWorkflowUnitClusterPk(si, _
                  parentWfProfileInfo.Name, "YourScenarioName", "YourApplicableTimePeriod"), _
             WorkflowProfileRelativeTypes.Descendants, _
             WorkflowProfileTypes.InputImportChild ))

    Getting the TextX Attributes for each base .Import profile:

    Dim textXAttribute As New List(Of String) 'will store the value of attribute from each profile
    
    For Each profile In baseWfProfileInfo
         textXAttribute.Add( _
            profile.GetAttribute( _
                scenarioType.TheAssociatedScenarioType.Id, _
                sharedconstants.WorkflowProfileAttributeIndexes.Text1 _
            ).Value ) 'I assume Text1 here
    Next

    At this point the textXAttribute is a list of strings containing the pieces you were after.  You can do your SFTP comparison logic against this.  Or turn this into a delimited string, etc. etc.

    One thing to note!  I'm assuming the textX attributes are stored at the .Import level.  If they are stored one level up you'll change the GetRelatives section.

     

    Whew!  Hope that makes sense or is enough to get you started in the correct direction.    Follow-ups are welcomed.

    Cheers!     -db

  • db_pdx's avatar
    db_pdx
    Valued Contributor

    Hi YanSavinsky: what's the end goal?  As is typical with OneStream there are often times multiple ways to achieve an outcome.  We might be able to recommend strategies with a clearer picture of the objective.

    To answer your question as listed: you'll be working with BRApi.Workflow.Metadata functions.

    Example: Getting your profile:  BRApi.Workflow.Metadata.GetProfile(...)

    Example: with your profile object, getting attributes: wfProfileInfo.GetAttribute(...)

    Some reference material: Solved: Workflow Profile's Substitution Text Settings in BRAPI rule - OneStream Community (onestreamsoftware.com)      |       Solved: BRAPI rule for getting Text field from Workflow - OneStream Community (onestreamsoftware.com)

  • YanSavinsky's avatar
    YanSavinsky
    New Contributor III

    Thank you for your reply, db_pdx.

     

    Currently I have a set of extender BRs that all do the same thing: connect to the SFTP server, look for a text file with a specific name and if the file is present pick it up, move it to OS Harvest folder and load it using a specific workflow profile. The rules are identical except for the name of the file the rule looks for and the workflow profile being used. The rules are engaged via steps in a DM sequence that runs on schedule. That means that several connection sessions to the SFTP server are created in quick secession. I would like to consolidate this process into a single BR running via a single step that will create a single connection session.

    I hope this provides enough of a context but please let me know if more is needed.

    Thanks again.

    Yan.

    • OS_Pizza's avatar
      OS_Pizza
      Contributor III

      YanSavinsky 

      Q1.  I would like to loop through all the "Import" steps within a specific node of workflow hierarchy

      Answer

       

      'Declare scenario and gtime.
      Dim parentWorkFlow as string = "parentWorkFlow Name"
      For Each pwf As String In parentWorkFlow
      					Dim wfClusterPk2 As WorkflowUnitClusterPk = BRApi.Workflow.General.GetWorkflowUnitClusterPk(si, pwf, scenario, gTime)
      					Dim objList As List(Of WorkFlowProfileInfo) = BRApi.Workflow.Metadata.GetRelatives(si, wfClusterPk2, WorkflowProfileRelativeTypes.Descendants, WorkflowProfileTypes.InputImportChild)
      					finalWFList.AddRange(objList)
      				Next

       

      Q2. To read the values of the "TextX" properties.

      Answer

       

      For Each w As WorkflowProfileInfo In finalWFList
      					If w.GetAttributeValue(ScenarioTypeID.Administration, textFieldUsed).StartsWith("Textfield Value") Then
      						
      					' Do all your load stuff	
      						
      					End If
      Next

       

       

      • db_pdx's avatar
        db_pdx
        Valued Contributor

        Ninja! 😛 lol.  But also your formatting is better!

    • db_pdx's avatar
      db_pdx
      Valued Contributor

      Yup! Makes total sense what you are striving for.  The generalized strategy would be:

      • Get your list of base Import profiles; either systematically (ideal) or from a manual list (simple/effective)
      • For each profile, get the TextX property and add to a list
      • Do your SFTP checks against the list

      If we just focus on the first two components it might look something like the below. For clarity I'll assume the following structure:

      Parent Level Workflow Group

      |---  Workflow1
               |----- Import
               |----- Forms
               |----- Adj
      
      |---  Workflow2
               |----- Import
               |----- Forms
               |----- Adj
      
      |--- Etc...

      Getting the list of .Import workflows (Workflow1.Import, Workflow2.Import):

      Dim parentWfProfileInfo As WorkflowProfileInfo = BRApi.Workflow.Metadata.GetProfile(si, _
          "Parent Level Workflow Group")
      Dim baseWfProfileInfo As New List (Of WorkflowProfileInfo)( _
          BRApi.Workflow.Metadata.GetRelatives(si, _
               BRApi.Workflow.General.GetWorkflowUnitClusterPk(si, _
                    parentWfProfileInfo.Name, "YourScenarioName", "YourApplicableTimePeriod"), _
               WorkflowProfileRelativeTypes.Descendants, _
               WorkflowProfileTypes.InputImportChild ))

      Getting the TextX Attributes for each base .Import profile:

      Dim textXAttribute As New List(Of String) 'will store the value of attribute from each profile
      
      For Each profile In baseWfProfileInfo
           textXAttribute.Add( _
              profile.GetAttribute( _
                  scenarioType.TheAssociatedScenarioType.Id, _
                  sharedconstants.WorkflowProfileAttributeIndexes.Text1 _
              ).Value ) 'I assume Text1 here
      Next

      At this point the textXAttribute is a list of strings containing the pieces you were after.  You can do your SFTP comparison logic against this.  Or turn this into a delimited string, etc. etc.

      One thing to note!  I'm assuming the textX attributes are stored at the .Import level.  If they are stored one level up you'll change the GetRelatives section.

       

      Whew!  Hope that makes sense or is enough to get you started in the correct direction.    Follow-ups are welcomed.

      Cheers!     -db