Tag Archives: Letter Activity

I’m finding the activities in MS CRM very frustrating to work with, especially the way the states are dealt with.

We just did our first mass-mailing from MS CRM and for the life of me couldn’t work out how to get it to record the activities as closed. Basically we setup a campaign, a marketing list, a campaign activity and then hit “Distribute Campaign Activity”.

However, this just creates me thousands of open activities which effectively show us “to-do” items for the owners of each account (or worse…me!). I googled for ages for a solution to this and only found some piss-poor excuses about it’s up to each Sales person to ‘own’ and deploy the items – ridiculous ! We just sent postal mailers to 1500 people and over 5,000 e-mails!! Sales people are here to sell, not stuff envelopes!

Anyway, having used the MS CRM UI to create the activities I need the activities closed so if a sales guy goes in to the account they can say with confidence “did you receive the mailer we sent you on 15th November?”. My first stab at this basically consisted of:

Creating a dataset and retrieving all of the activities that need altering by querying the filtered views, something like (alter to your needs !!!):

SELECT FilteredActivityPointer.activityid,
[FilteredActivityPointer].[statecodename]
FROM FilteredCampaignActivity
INNER JOIN FilteredCampaignActivityItem
ON FilteredCampaignActivity.activityid = FilteredCampaignActivityItem.campaignactivityid
INNER JOIN FilteredActivityPointer
ON FilteredActivityPointer.regardingobjectid = FilteredCampaignActivity.activityid
AND FilteredCampaignActivity.channeltypecodename = FilteredActivityPointer.activitytypecodename
WHERE FilteredActivityPointer.[statecodename]='Open' -- Only open account/contact activities
AND [FilteredCampaignActivity].[subject] LIKE 'Mailer%' -- Name of the Campaign activity (ideally use a Guid instead)

This gives us a list of ActivityIds that need to be ‘closed’, I simply call the GetData method on my dataset to give me a list I can foreach through.

Thus for each open Activity I must iterate through, set the actualendtime and then set the state to close (some helper snippets by David Padbury):

This isn’t meant to be a complete solution, but hopefully will give you enough pointers to be useful, especially with regard to other entity types. I have to say the MS CRM SDK is pretty useless, and the classes are pretty poorly documented