Thursday 6 March 2008

Create recurring tasks or activities in CRM 3.0

There was a troubleshooting general issue in Microsoft Dynamics CRM 3.0 in regards to creating recurring activities such as appointment, service activity or tasks which is NOT possible to do in CRM.

The Q&A can be found at the following link:

http://www.microsoft.com/dynamics/crm/using/troubleshooting/tsgeneral.mspx

How do I create recurring appointments and service activities?
A. You cannot create recurring appointments or service activities in Microsoft Dynamics CRM. Appointments and service activities are created one at a time. If a recurring appointment is created in Microsoft Dynamics CRM client for Microsoft Office Outlook, the recurrence will be lost after synchronization with Microsoft Dynamics CRM.


Anyhow, I had a requirement to allow the users to create recurring tasks in CRM 3.0 task activity in particular. It should be noted that this is a lot easier to do in CRM 4.0 as all you would need is a simple workflow to create the recurring tasks when the initial task is being created.

This added feature shall simply capture the start and end dates of the recurrence event. It also captures the recurring pattern (i.e. Daily, Weekly, Monthly, Quarterly or Annually).

I then added a number of attributes and a new tab in the task activity to capture the above info and based on that I created a callout to create the tasks based on the values entered in the above fields as shown below.



The following code snippet is taken from the callout showing how the tasks have been created based on the recurring pattern inserted by the user.

// if recurring is set to Yes and recurring dates are
also set then create the additional tasks

if(new_isrecurring && new_recurringstart != string.Empty && new_recurringend != string.Empty && new_recurringpattern != 0)
{
DateTime addRecurringStartDate = DateTime.Parse(new_recurringstart);

DateTime addRecurringEndDate = DateTime.Parse(new_recurringend);


while
(addRecurringStartDate < addRecurringEndDate)
{

// Re-Assign the new_recurringstart & new_recurringend
new_recurringstart = addRecurringStartDate.ToString();
new_recurringend = addRecurringEndDate.ToString();

switch
(new_recurringpattern)
{

case
1: //Daily
addRecurringStartDate = addRecurringStartDate.AddDays(1);

if(addRecurringStartDate <= addRecurringEndDate)
// Call the Create Task method here
CreateAdditionalTask(....);
break;

case 2: //"Weekly":
addRecurringStartDate = addRecurringStartDate.AddDays(7);

if(addRecurringStartDate <= addRecurringEndDate)
// Call the Create Task method here
CreateAdditionalTask(....);
break;

case 3: //"Monthly":
addRecurringStartDate = addRecurringStartDate.AddMonths(1);

if
(addRecurringStartDate <= addRecurringEndDate)

// Call the Create Task method here
CreateAdditionalTask(....);
break;

case
4: //"Quarterly":
addRecurringStartDate = addRecurringStartDate.AddMonths(3);

if(addRecurringStartDate <= addRecurringEndDate)
// Call the Create Task method here
CreateAdditionalTask(....);
break;

case 5: //"Annually":
addRecurringStartDate = addRecurringStartDate.AddYears(1);

if(addRecurringStartDate <= addRecurringEndDate)
// Call the Create Task method here
CreateAdditionalTask(....);
break;


Obviously, you will need to call the CRMService web service and create the tasks from your callout.

In addition, you may need to cater for bank holidays and weekends and exclude them from your calculation of days, weeks, monthly and years. There was not a need to do that in this particular instance but if you need a guideline on how to do it or have any further queries regarding any of the above then please post it here or email me with it.


8 comments:

Anonymous said...

Can you explain a bit further what you mean by
"Obviously, you will need to call the CRMService web service and create the tasks from your callout."

Also, is the provided code snippet entered under the "OnSave" event for the newly created tab/form. If so can you provide the "CreateAdditionalTask" function.

Unknown said...

You will need to make a call to CRM web service to create the task using the outlined methods of creation and the code is the callout .net code (server-side code not client-side jscript...)

Anonymous said...

does the reoccuring task appear on user's outlook calendar too? w/reminders etc., Boss doesn't want to have to add /update in two places.... thanks!

Anonymous said...

does this workflow make it so the recurring task is both in the Activies of the Client record and the oulook tasks of the user?
Thanks!

Unknown said...

this simply creates multiple tasks and work out the dates and time as specified. So, when CRM sync with Outlook, you will see multiple tasks in outlook as you would also see multiple tasks in CRM as CRM does not support re-occurring task unlike Outlook.

It's really a work around create re-occurring task.

Unknown said...

It is possible to create reccuring appointments in MS CRM 4.0 with form customization as well.

You can visit

http://stackoverflow.com/questions/2517914/recurring-appointments-in-dynamics-crm/3646164#3646164

OR

http://social.microsoft.com/Forums/en-US/crmdevelopment/thread/3f020e02-cd86-44b2-9cff-36e6cdafc8d8

Anonymous said...

Awesome, that’s exactly what I was scanning for! You just spared me alot of searching around

Anonymous said...

hi, good site very much appreciatted