Microsoft Dynamics 365 Blog

It has been 9 months since I last blogged on the CRM blog. All this time I have been working on the Titan features unrelated to workflow. Very recently I was pulled in to get some workflow bugs done and also to provide my insight to the CRM 3.0 to Titan compatibility. To tell you my first impression was WOW! Titan workflow will give the user the missing edge they always wanted. User level workflow, easy and flowing UI for construction and maintenance, visibility to what automated processes are running, what the current stage is etc right from the entity instance and most important. There are no arbitrary restrictions. Microsoft Dynamics CRM 4.0 has most of the things that I would have wished for and that I have seen users asking for on the newsgroups. I am sure you are going to just love it.

Check out, some screencasts at Phil Richardson’s blog.

Coming to today’s article I would like to discuss on a very common scenario. “Workflow rule to flag neglected cases”. I have read many people asking for this and the solution proposed generally are very specific. This is an advance solution via CRM 3.0 workflow and so will definitely require writing some .net custom assembly code. But let’s put some hard requirements on the solution and try to cover them all.

1) It should have low maintenance overhead.

2) It should have easier and flexible way to specify the criteria for search.

3) The search criteria should be easily accessible and easy to update.

4) The solution can be turned off and on without additional hoops.

5) The search result should be easily viewable and verifiable.

6) The search result should be available on demand.

7) The solution should be easily extendable to other similar scenarios.

Scenario: Workflow rule to flag neglected cases. There could be many different conditions that can server the purpose. Few examples could be.

a) Cases that have no activity created in last 2 days.

b) Cases that have no service activity associated with them.

c) Cases that have not be updated in last 2 days

Approach: We would use the richness and flexibility of advance find to define our search criteria. Next we write a small .net assembly action that will run ‘advanced find’ and return the number of records in it. The returned integer (# of records in the advanced find search) can then be used to define a condition to perform some actions.

Steps:

  1. Create a .Net assembly that will take in a workflow caller (this is an xml in the format “<caller><userid>684F160A-E4D9-4C3C-ADDD-1464D2B14EB2</userid><merchantid>F671739E-189A-4EE8-AF86-66DC8CF5F6C4</merchantid></caller>”) and advance find guid.

Today I will only give you the basic function definition. If you require more help in writing .net assembly actions for workflow you can refer to my other articles or look on the Microsoft site.

namespace CrmTest

{

public class Test

{

public int Execute(string callerXml, Guid advanceFindId)

{

// 1) Retrieve the adv find user query.

// 2) Check if the adv. find query is active.

// 2) If yes, execute fetch with the adv. find criteria.

// 3) Return the row count returned.

}

}

}

  1. Register the .NET assemblies as below and restart the workflow service.

<method name=”AdvanceFind”

assembly=”workflowtestassembly.dll ”

typename=”CrmTest.Test”

methodname=”Execute”

group=”My Custom Actions”

timeout=”7200″>

<parameter name=”Caller” datatype=”caller”/>

<parameter name=”AdvanceFindId” datatype=”lookup” entityname=”userquery”/>

<result datatype=”integer”/>

</method>

  1. Create a Advance find query with name “Neglected Cases”. For now put some search criteria in it and save it.
  2. Create a manual workflow rule on case with name “Flag neglected cases”.

a. Manual rule

clip_image002

b. Advance find action.

clip_image004

  1. Activate the workflow rule and apply it to any case.

Solution check: Did we fulfill all our requirements?

The workflow rule is a simple flexible one. It can be used on any entity and different conditions can be created on the return value. You can make the workflow rule do complex actions or leave it simple as to email a user with the results. The link to the adv find query can be placed inside the email for easy accessibility. The adv find link would look something like:

http://<ServerName>/advancedfind/advfind.aspx?EntityCode=1&QueryId={3F5159BA-967C-DC11-A636-0013720EC2DB}&ViewType=4230

The search criteria associated is in the advance find query. You can create lot of complex queries and this can be modified over time using the web browser. No need to update the workflow rule when the requirements changes. To turn off the notifications (as required) just disable the ‘advanced find’ query. The code will detect that the query is inactive and will return zero count.

The solution elegantly combines the power of ‘advanced find’ and workflow to find neglected cases.

Note: If you want to control the scope of the user applying the rule look at “controlling scope of Apply rules”.

Enjoy,

Shashi Ranjan

We're always looking for feedback and would like to hear from you. Please head to the Dynamics 365 Community to start a discussion, ask questions, and tell us what you think!