Displaying On Demand Workflows in sorted order in Dynamics CRM 2013

Recently we had a requirement where we needed to display a specific set of on demand workflows in a specific order for a particular entity. Well is this possible? In a supported way? The answer is No. However if your customer is hell bent on this, you can try the below unsupported approach. This solution is only applicable to on-premise environments.

Go to CRM database and pull out the fetchxml for the saved query with name = “On demand Workflows”

select savedqueryid, fetchxml from savedquery where name = ‘On demand workflows’

The following is the fetchxml you would receive.

<fetch version=’1.0′ mapping=’logical’>
  <entity name=’workflow’>
    <attribute name=’workflowid’ />
    <attribute name=’name’ />
    <attribute name=’category’ />
    <attribute name=’createdon’ />
    <attribute name=’modifiedon’ />
    <attribute name=’statecode’ />
    <attribute name=’owningbusinessunit’ />
    <attribute name=’ownerid’ />
    <filter type=’and’>
      <condition attribute=’type’ operator=’eq’ value=’1′ />
      <condition attribute=’ondemand’ operator=’eq’ value=’true’ />
      <condition attribute=’statecode’ operator=’eq’ value=’1′ />
      <filter type=’or’>
        <condition attribute=’category’ operator=’eq’ value=’0′ />
      </filter>
    </filter>
  </entity>
</fetch>

Many of you might have already guessed that this fetchxml needs to be updated with a sort order. However on which column do we need a sort. Well this depends on the requirement. If you need to sort it alphabetically, then you should sort on the name. But if you need to display it some other specific order, here is trick.

Deactivate the workflows and re-activate the workflows in the sequence you wish to display them. Then add the following sort order.

<order descending=’false’ attribute=’modifiedon’ />

The final fetchxml would look like this.

<fetch version=’1.0′ mapping=’logical’>
  <entity name=’workflow’>
    <attribute name=’workflowid’ />
    <attribute name=’name’ />
    <attribute name=’category’ />
    <attribute name=’createdon’ />
    <attribute name=’modifiedon’ />
    <attribute name=’statecode’ />
    <attribute name=’owningbusinessunit’ />
    <attribute name=’ownerid’ />
    <order descending=’false’ attribute=’modifiedon’ />
    <filter type=’and’>
      <condition attribute=’type’ operator=’eq’ value=’1′ />
      <condition attribute=’ondemand’ operator=’eq’ value=’true’ />
      <condition attribute=’statecode’ operator=’eq’ value=’1′ />
      <filter type=’or’>
        <condition attribute=’category’ operator=’eq’ value=’0′ />
      </filter>
    </filter>
  </entity>
</fetch>

Update the fetchxml of the saved query. And voila! you are done.

Hope this helps!

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s