Recipe - Workflow Finder
Skill level: Intermediate
Organization: First Church of God of Columbia City
Requires Rock: 1.14.0
{# strip images & classes from the HTML but otherwise leave structure #}
Based on the original Workflow User Entry Page Finder recipe by David Benson.
On the Workflow Type Configuration page, easily see where a particular Workflow is used.
Lists if a Workflow Type is used in the following:
- Page Blocks with a User Entry form statically configured for the Workflow Type
- workflowactivate Lava in HTML Content Blocks and Block Pre/Post (static/fixed workflowtypeid parameter only)
- General Workflow Triggers
- Connection Type/Opportunity Triggers
- Step Type/Program Triggers
- (more - to be added...)


Steps:
- Go to the General Settings > Workflow Configuration (/admin/general/workflows)
- Hover and click on Page Zones (or Alt+Z). Click the Main Zone, add a new HTML Content block. (name = Where Used)
- Hover and click on Block Configuration (or Alt+B). Click on Block Properties for the new Where Used Block. Enable Rock Entity and SQL Lava Commands.
- Click on Edit HTML for the new Where Used Block. Copy paste the Lava from below.
<!-- Workflow Type - Where Used block -->
{% assign workflowTypeId = 'Global' | PageParameter:'workflowTypeId' | Default:null %}
{% assign thisPageId = 'Global' | Page:'Id' %}
{% assign hrefRoot = 'Global' | Attribute:'InternalApplicationRoot' %}
{% if workflowTypeId != empty and workflowTypeId != null %}
<!-- get the guid of the workflowtype -->
{% workflowtype id:'{{ workflowTypeId }}' securityenabled:'false' %}
{% assign workflowTypeGuid = workflowtype.Guid %}
{% endworkflowtype %}
<!-- display if used by any (entity) triggers -->
{% workflowtrigger where:'WorkflowTypeId == "{{ workflowTypeId }}' securityenabled:'false' count:'true' %}
{% if count > 0 %}
<div class='alert alert-default'>
This Workflow is currently being used by a <a href='{{ hrefRoot }}/admin/general/workflow-triggers'>Workflow Trigger</a><br/>
</div>
{% endif %}
{% endworkflowtrigger %}
<!-- find all the blocks that have a user entry block with a workflow selected (this may need additional paramters if you have similar custom blocks) -->
{% attribute where:'Name *= "Workflow Type" && EntityTypeQualifierValue == 264' securityenabled:'false' %}
{% attributevalue where:'AttributeId == {{ attribute.Id }} && Value *= "{{ workflowTypeGuid }}"' securityenabled:'false' %}
{% assign itemValues = attributevalueItems %}
{% assign itemSize = attributevalueItems | Size %}
{% endattributevalue %}
{% endattribute %}
<!-- display user-entry blocks -->
{% if itemSize > 0 %}
<div class='alert alert-default'>
This Workflow is currently being used via user entry on the following pages:<br/>
<ul>
{% for attributeValue in itemValues %}
{% block where:'Id == {{ attributeValue.EntityId }}' securityenabled:'false' %}
<li><a href='{{ hrefRoot }}/page/{{ block.Page.Id }}' target='_blank'>{{ block.Page.BrowserTitle }}</a></li>
{% endblock %}
{% endfor %}
</ul>
</div>
{% endif %}
<!-- find all blocks that have a workflowactivate lava in Pre/Post or HTML Content block -->
{% assign blockIDs = '[]' | FromJSON %}
{% sql %}
DECLARE @wfId nvarchar(50);
SET @wfId = '{{ workflowTypeId }}';
SELECT
TOP 10 *
FROM
[Block]
WHERE
(
PreHtml LIKE '%workflowactivate %' AND
PreHtml LIKE '% workflowtypeid:'''+@wfId+'''%'
) OR
(
PostHtml LIKE '%workflowactivate %' AND
PostHtml LIKE '% workflowtypeid:'''+@wfId+'''%'
)
{% endsql %}
{% for block in results %}
{% assign blockIDs = blockIDs | AddToArray:block.Id %}
{% endfor %}
{% sql %}
DECLARE @wfId nvarchar(50);
SET @wfId = '{{ workflowTypeId }}';
SELECT
TOP 10 *
FROM
[HtmlContent]
WHERE
Content LIKE '%workflowactivate %' AND
Content LIKE '% workflowtypeid:'''+@wfId+'''%'
{% endsql %}
{% for content in results %}
{% assign blockIDs = blockIDs | AddToArray:content.BlockId %}
{% endfor %}
{% if blockIDs != empty and blockIDs != null %}
{% block ids:'{{ blockIDs | Join:',' }}' %}
<div class='alert alert-default'>
This Workflow is refernced by workflowactivate Lava in following pages:<br/>
<ul>
{% for item in blockItems %}
<li><a href='/page/{{ item.Page.Id }}'>{{ item.Page.BrowserTitle }}</a> ({{ item.Name }} block)</li>
{% endfor %}
</ul>
</div>
{% endblock %}
{% endif %}
<!-- find all connection types/opportunities that have this workflow type -->
{% connectionworkflow where:'WorkflowTypeId == "{{ workflowTypeId }}"' securityenabled:'false' %}
{% assign itemSize = connectionworkflowItems | Size %}
{% if itemSize > 0 %}
<div class='alert alert-default'>
This Workflow is currently being used by the following Connections:<br/>
<ul>
{% for connectionworkflowValue in connectionworkflowItems %}
<li>
{% if connectionworkflowValue.ConnectionOpportunity.Id != empty and connectionworkflowValue.ConnectionOpportunity.Id != null %}
<a href='{{ hrefRoot }}/people/connections/types/{{ connectionworkflowValue.ConnectionOpportunity.ConnectionTypeId }}/opportunity/{{ connectionworkflowValue.ConnectionOpportunity.Id }}' target='_blank'>{{ connectionworkflowValue.ConnectionOpportunity.Name }}</a> (Connection Opportunity)
{% else %}
<a href='{{ hrefRoot }}/people/connections/types/{{ connectionworkflowValue.ConnectionType.Id }}' target='_blank'>{{ connectionworkflowValue.ConnectionType.Name }}</a> (Connection Type)
{% endif %}
</li>
{% endfor %}
</ul>
</div>
{% endif %}
{% endconnectionworkflow %}
<!-- find all step programs/types that have this workflow type -->
{% stepworkflowtrigger where:'WorkflowTypeId == "{{ workflowTypeId }}"' securityenabled:'false' %}
{% assign itemSize = stepworkflowtriggerItems | Size %}
{% if itemSize > 0 %}
<div class='alert alert-default'>
This Workflow is currently being used by the following Steps:<br/>
<ul>
{% for stepworkflowValue in stepworkflowtriggerItems %}
<li>
{% if stepworkflowValue.StepType != empty and stepworkflowValue.StepType != null %}
<a href='{{ hrefRoot }}/steps/type/{{ stepworkflowValue.StepType.Id }}' target='_blank'>{{ stepworkflowValue.StepType.Name }}</a> (Step Type)
{% else %}
<a href='{{ hrefRoot }}/people/steps/program/{{ stepworkflowValue.StepProgram.Id }}' target='_blank'>{{ stepworkflowValue.StepProgram.Name }}</a> (Step Program)
{% endif %}
</li>
{% endfor %}
</ul>
</div>
{% endif %}
{% endstepworkflowtrigger %}
{% endif %}
Above Lava can be used in Lava Tester - just change the null to a WorkflowType Id
See anything you'd like added? - comment, and I'll try to implement it.