Forum Discussion

Sergey's avatar
Sergey
Contributor III
3 years ago

Connector Business Rule filtered for workflow profile entities

Dear community,

 

I have a Connector-type business rule that works like a charm.

However, the SQL query which is the source of this connector is currently returning data for all entities, while this should be use for each entities that are affected to the given workflow profile.

 

--> What is the best way to achieve a connector business rule that would be filtered by workflow profile entities ? Any exemples out there ?

 

Best Regards,

  • db_pdx's avatar
    db_pdx
    Valued Contributor

    Hi Sergey: I don't have any active connectors that do this sort of filtering, but I don't see any reason why you wouldn't be able to add the filter directly into the connector.

    Conceptually, you'll need the following (starting with the end in mind and working backwards through the components).

    • A new/update WHERE clause in the connector.  An IN(entityFilter)
    • The entityFilter which contains of a delimited list of the applicable entities
    • The list of applicable entities based on the current workflow

    The components to do that might look like (now inverting the order to build up to the final WHERE clause)

    'Get our workflow profile entities based on the active workflow
    Dim profileEntityInfo = New List(Of WorkflowProfileEntityInfo)(BRApi.Workflow.Metadata.GetProfileEntities(si, si.WorkflowClusterPk.ProfileKey))
    'Convert to List(Of String) with only the EntityName.
    Dim profileEntityInfoString = New List(Of String)(profileEntityInfo.ConvertAll(Function(x) x.EntityName))
    'Create the entityFilter for use in the SQL WHERE clause
    Dim entityFilter As String = SqlStringHelper.CreateInList(profileEntityInfoString,True,False)
    'Add to our SQL query. NOTE! This asssumes you are using a text.stringbuilder()
    sql.AppendLine("WHERE YourColumnThatContainsEntity IN(" & entityFilter & ")")

     

    Again, I haven't tested this in a connector, but hopefully it sets you on the right track.

    Cheers -DB

    EDIT:

    The GetProfileEntities line might need to use api.WorkflowUnitPk.ProfileKey rather than si.WorkflowClusterPk.ProfileKey so it has the correct context.  I wrote the above by playing in an extender rather than a connector rule, so please test.

  • Sergey's avatar
    Sergey
    Contributor III

    Hi !

    I was working on your code, it turns out that there is a snippet "Assign string of entities as array" that is doing exactly what we are trying to achieve, only the name was misconducting.

     

    It's working now ! 🙂

     

    Regards,