Muhammad Ali Khan

MS CRM 3.0, MS CRM 4.0, Sharepoint 2007 & Sharepoint 2010

Posts Tagged ‘Auto Refresh MS CRM Marketing List’

Auto Refresh Marketing List In MS CRM 4 Using Workflow

Posted by Ali Khan on February 21, 2010

Creating Marketing List & Campaign is one of the common tasks in MS CRM. With dynamic nature of the data, members of the marketing list may change daily, weekly or monthly and hence they need to be re-evaluated frequently.

MS CRM 4 supports evaluating, adding, removing members from a marketing list even if the list is in a running campaign (unless the list is locked), but unfortunately these operation have to be pre-form manually, there is no such feature as “Auto Refresh Marketing List” on daily or weekly or monthly basis.

With above requirement in mind, I have create a simple workflow that can run daily on a marketing list and evaluates whether the new members have to be added to the list or some existing member has to be removed from the list since it now longer matches the criteria for which the list was created.

I have created two workflows for this purpose:-

My First workflow, “Auto Refresh Marketing List” takes two parameters and refreshes the marketing list on which it is run. These parameters actually define the criteria of the marketing list members. These parameters are:-

Parameter Name Value Direction
UserQueryID A Guid of User View (userquery), In case you want to refresh the marketing list against a particular user defined view. Input
FetchXml If you don’t have the view id and you have the fetchxml, you can specify in this parameter. Input

 

My Second workflow “Get Next Day” is a simple workflow that returns me the workflow next run date and it will help me in running my workflow daily.

Parameter Name Value Direction
InitialDate Set to the last Refresh Date Input
NextDate InitialDate + 1, Returns the Next Date on which the workflow should run Output

 

To refresh/evaulate any marketing list members, I used the “QualifyMemberListRequest” Request from “MS CRM Sdk”. The code logic is pretty straight forward.

a) Fetch all the members that matches the View (UserQueryID) or the FetchXml.

b) Use the “QualifyMemberListRequest” to qualify (add or remove) the marketing list members.

Here is the sample code. You can download the full code (with support for account, contact, lead list and FetchXml) from here: – Download Source Code

image

Setup the Refresh Marketing List Workflow:-

1) Download the code and register the assembly using the “MS CRM Plugin Registration Tool”.

2) You can also export the workflow and the list customization from the “customization.xml” attached.

image

Or you can follow the steps below.

3) Create a variable “RefreshDate” of type “DateTime” in the entity “list”, as show below

image

4) Create a new workflow name it “Auto Refresh Marketing List” on the “list” entity. I configured my workflow to run on “On Demand” and on the change of the attribute “Refresh Date” as shown below.

image

image

5) Now here is the logic of the workflow

·         NextDate = “Get Next Day”(workflow)

·         If Marketing List. RefreshDate Contains Data then

                Timeout Until MarketingList.RefreshDate then

                                Run “Auto Refresh Marketing List(workflow)

·         Update MarketingList. RefereshDate = NextDate

 

6) Here is how i configure it.

a. Clickclip_image002[3], and then go to “My Custom Workflows” è “Get Next Day” and add this workflow activity.

b. Configure the input parameter (InitialDate) for the workflow “GetNextDay” as shown below.

image

c. Now click “Add Step” and this time click “Add Condition”, click on “click to configure conditon” , to configure the following condition as shown below.

image

d. Now add a “Wait Condition”, and click on “click to configure condition”, to configure the wait until “RefreshDate” as shown below.

image

e. Click on the “Select this row and add step” and the click on “Add Step” and add this time add the “Auto Refresh Marketing List”. “MyCustom Workflows” ==> “Auto Refresh Marketing List”. Now configure the parameters as show below, you can either specify the “View ID” or you can specify the “Fetchxml”. Note, I have specified a hard coded “ViewID” but this value can come from any dynamic variable from the list entity.

image

f. Final step, add a new step “Update Record” to update the “RefreshDate” of the “list” entity, as shown below. Note: – I added the “RefreshDate” on the main form (for debugging purpose only), but better NOT to add it on the main form and update it on the “Additonal Fields” tab. This will avoid triggering of the workflow accidently from the user if he changes the “RefreshDate” on the main form in the application.

image

g. Now publish the workflow, it should look like this now.

image

7) Now create a test list, and apply the workflow as shown below, it will refresh the list automatically. Update the “RefreshDate” and will launch another instance of “Auto Refresh marketing list” that will wait unit the “RefreshDate” happens, i.e. Tomorrow.

image

image

image

image

8) Here is my custom view.

image

9) Finally, you can download the “Source Code”, the customized “List form” and the “workflow template”, from here (Download)

Note: – If you have difficulty in writing “FetchXml”, use this tool “Fetch Xml Builder” to generate the FetchXml for you.

That’s all folks.

Posted in MS CRM 4 Workflows, MS CRM 4.0 | Tagged: , , | 5 Comments »