SQL Query to get list of accounts a user manages

SQL Query to get list of accounts a user manages

Comments

  • [font=Roboto, Arial, Helvetica, sans-serif]Im using the following query to get the list of accounts that a user is managing: [/font]
    [font=Roboto, Arial, Helvetica, sans-serif]
    [/font]
    [font=Roboto, Arial, Helvetica, sans-serif]"SELECT concat(concat(ea.first_name, ), ea.last_name) FROM account_relation ar JOIN entity_account ea ON ea.account_id=ar.account_id where ar.entity_name like %Manager% and ar.deleted = False and ar.to_account_id = @account_id;" [/font]
    [font=Roboto, Arial, Helvetica, sans-serif]
    [/font]
    [font=Roboto, Arial, Helvetica, sans-serif]Instead of passing a parameter with account_id is it possible to get current user account id as a subquery so that I can the query looks like this: "SELECT concat(concat(ea.first_name, ), ea.last_name) FROM account_relation ar JOIN entity_account ea ON ea.account_id=ar.account_id where ar.entity_name like %Manager% and ar.deleted = False and ar.to_account_id = (subquery to get account id of current user);"[/font]

  • [font=Roboto, Arial, Helvetica, sans-serif]The context of the user running the flow is only available from a Decisions servers memory by mapping in Flow Data > CurrentUserId or Current Account.AccountId. Using a parameterized query to accept that dynamic input is your best option. Other methods to do this would take more server resources and effort to implement than a parameterized query.[/font]

Sign In or Register to comment.