Purpose

I often find myself writing workflows where an email, notification, or assignment needs to be sent to a specific staff role, like an admin assistant for a department. The hard part is that when that staff person leaves, all of the workflows that reference that person now need to be updated. This solution allows you to specify a role within the workflow that will dynamically pull in the correct person profile based on that person's role, leaving you with only one place to change the reference if that staff person leaves instead of hunting down all the places you've referenced them.

By default it returns the Guid of the first returned Person's PrimaryAlias, but you can pass an optional parameter, scope, that will return a comma-separated list of PrimaryAlias Guid's if multiple of your staff have the same title.


Assumptions/Prerequisites

  • This solution utilizes the built-in Organization Unit group type. Note: If you aren't already using it, there's an Org Chart page under Office Information that allows you to edit the staff structure of your church. The code doesn't rely on the structure, simply the group type, so structure it however it makes sense for your church!

        Screen_Shot_2020-07-16_at_9.55.23_AM.png


Process

There's just two things we need to do to set it up, then it's easy to use from there! We're going to add your staff's titles as individual roles in the Organization Unit group type, and then we'll create a Lava shortcode to retrieve the value(s) we need.

Adding Staff Titles
  1. Head to the `Group Types` page (Rock Settings > General Settings, click Group Types) and click on the Organization Unit group type.
  2. Expand Roles and add all the staff titles you have, then click Save to save the group type.
    •    Screen_Shot_2020-07-16_at_10.55.32_AM.png
    • Note: The Is Leader designation doesn't matter for this purpose, but I marked them correctly in case we ever needed them later.
Create a Lava shortcode
  1. Head to the Lava Shortcodes page (Rock Settings > CMS Configuration, click Lava Shortcodes).
  2. Click the "+" button in the top right corner to create a new shortcode.
    • Name: "Get Staff Person by Title"
    • Tag Name: staffbytitle
    • Tag Type: Inline
    • Description: Returns the Primary Alias Guid of the staff member when provided with a Group Role ID. Optional flag to add if you want all of the staff members with that title, otherwise it returns only the first.
    • Documentation:
      • {[ staffbytitle grouproleid:'"{{ groupRoleId }}"' ]} or {[ staffbytitle grouproleid:'"{{ groupRoleId }}"' scope:'all' ]}
    • Shortcode Markup: (listed below)
    • Enabled Lava Commands: RockEntity
    • Parameters:
      1. grouproleid {no default value}
      2. scope {default value: first}

    Shortcode Markup:

    {% assign returnvalue = '' %}
    {% groupmember where:'GroupRoleId == "{{ grouproleid }}"' %}
        {% if scope == 'all' %}
            {% for member in groupmemberItems %}
                {% if forloop.last %}
                    {% assign returnvalue = returnvalue | Append:member.Person.PrimaryAlias.Guid %}
                {% else %}
                    {% assign returnvalue = returnvalue | Append:member.Person.PrimaryAlias.Guid %}
                    {% assign returnvalue = returnvalue | Append:',' %}
                {% endif %}
            {% endfor %}
        {% else %}
            {% assign gm = groupmemberItems | First %}
            {% assign returnvalue = gm.Person.PrimaryAlias.Guid %}    
        {% endif %}
    {% endgroupmember %}
    {{ returnvalue }}

     

    Completed Shortcode Screenshot:

    Screen_Shot_2020-07-16_at_11.07.34_AM.png


    How to Use It

    Note: this is the method that returns a single staff person. I've not yet had to return multiple, but the shortcode will allow it if you need. You'd just want to have your second attribute be a text attribute so you could split it into an array and loop through it to do what you need.

    This is super simple to use, you just need to create two attributes in your workflow and add a single action to run the shortcode!

    Attributes

    You need to add a Person attribute, which is used as your recipient in your assignment / email / notification action, then a Group Role attribute. This Group Role attribute will have a default value for the staff position that needs the email / assignment / notification.

    Screen_Shot_2020-07-16_at_11.17.14_AM.pngScreen_Shot_2020-07-16_at_11.20.31_AM.png

    Action

    The action will simply take the group role specified in your attribute, and assign the result to the Person attribute!

    It'll a be Lava Run Action, and it'll look like this:

    Screen_Shot_2020-07-16_at_11.21.48_AM.png

    Here's the code you can copy/paste, just remember to change the Attribute Key to whatever it is in your workflow:

    {% assign groupRoleId = Workflow | Attribute:'FacilitiesAdminAssistantGroupRole','Object' | Property:'Id' %}
    {[ staffbytitle grouproleid:'"{{ groupRoleId }}"' ]}

    You can now use the Person attribute wherever you need in your workflow, and if that staff person leaves, you just update your organization structure once and never have to update the workflow!