Coding Snippets

Output Workflow/Activity Attributes using Lava

This is a quick way to output a formatted list of all the attributes of a workflow or an activity (e.g. to quickly output the answers from a form to a memo field on an entity or in an email or in a PDF)

<dl>
    {%- for attribute in Workflow.AttributeValues -%}
        <dt>{{ attribute.AttributeAbbreviatedName }}</dt>
        <dd>{{ attribute.ValueFormatted }}</dd>
    {%- endfor -%}
</dl>

<dl>
    {%- for attribute in Activity.AttributeValues -%}
        <dt>{{ attribute.AttributeAbbreviatedName }}</dt>
        <dd>{{ attribute.ValueFormatted }}</dd>
    {%- endfor -%}
</dl>

To limit the output to a subset of attributes - add an underscore (_) to the front of the AttributeKey...

<dl>
    {%- for attribute in Workflow.AttributeValues -%}
        {%- assign keyPrefix = attribute.AttributeKey | Slice:0,1 -%}
        {%- if namePrefix == '_' -%}
            <dt>{{ attribute.AttributeAbbreviatedName }}</dt>
            <dd>{{ attribute.ValueFormatted }}</dd>
        {%- endif -%}
    {%- endfor -%}
</dl>

Delimited Lists with Sets and Items

These are my standard delimiters when I'm creating a list in a workflow for loop processing. The set delimiter separates what gets passes as input into each loop. The item delimiter is used to pass multiple 'things' in that input (e.g. a person GUID, an action, a message, etc)

{%- assign setDelimiter = '^|^' -%}
{%- assign itemDelimiter = '_^_' -%}

SQL - Joining to Person via Person Alias

SELECT  stuff
FROM    [SomeTable] st
INNER JOIN  [PersonAlias] pa
    ON  pa.[Id] = st.[PersonAliasId]
INNER JOIN  [Person] p
    ON  p.[Id] = pa.[PersonId]

SQL - Joining to Attribute Value

This shows an example of joining GroupMember table to the Attribute Value table to get a couple group member attributes - 1 required and 1 optional. Replace the 9999's for Ids with the actual Ids of your attributes.

DECLARE @GroupId INT
    , @RequiredAttrId INT
    , @OptionalAttrId INT;

SET @GroupId = 9999;
SET @RequiredAttrId = 9999;
SET @OptionalAttrId = 9999;

SELECT  stuff
FROM    [GroupMember] gm
INNER JOIN  [AttributeValue] requiredAV
    ON  requiredAV.[AttributeId] = @RequiredAttrId
    AND requiredAV.[EntityId] = gm.[Id]
    AND requiredAV.[Value] = 'Some Value'
LEFT JOIN  [AttributeValue] optionalAV
    ON  optionalAV.[AttributeId] = @OptionalAttrId
    AND optionalAV.[EntityId] = gm.[Id]
WHERE   gm.[GroupId] = @GroupId

Comments are anonymous (unless you happen to have a Crossing account) - so please include your Name (and your email if you would like a response)