Friday, March 4, 2011

Determining if an Account is a part of a DitributeCampaignActivity


Scenario: Given an account GUID, I should be able to determine if the account is a part of a  "Distribute  Campaign Activity"
The functional flow of the data would be CampaignCampaign ActivitiesCampaign Activity ItemTarget Marketing ListsMarketing List MembersAccounts
 I was trying to look into the database for my answers and before reaching the solution, the following are my findings:
1.       List and ListMember are the tables that contain the data about a marketing list
2.       Similarly, Campaign and CampaignActivity tables contain information about the Campaign records.
3.       Intersect Tables: When there is a many-to-many relationship between two entities, an intersect table is created. This is true for both system relationships built in to the product as well as custom many-to-many relationships. This is how we used to create M:M relationships in CRM 3.0 but it’s implemented OOB in CRM 4.0(See “Using Intersect Tables” in SDK for more info)
4.       The Intersect Table between List and CampaignActivity isCampaignActivityItem.
5.       There is also a ‘DistributeCampaignActivity’ message using which we can distribute a campaign programmatically. However, we cannot register a plugin against this message as it’s not supported.
6.       So, although I was getting all the info individually, I was still not able to determine if an account was a part of a DistributeCampaignActivity.
7.       Then I found that all the plugin registration messages are stored in theSdkMessageBase and the SdkMessageFilterbase tables and there was a‘DistributeCampaignActivity’ message in the table but it was not exposed.
8.       So, I used the below query  in order to expose the‘DistributeCampaignActivity’ message in the plugin registration tool.(Unsupported)

update sdkmessagefilterbase
set isCustomProcessingStepAllowed=1
where sdkmessageid=(select sdkmessageid from sdkmessagebase where name='DistributeCampaignActivity')
9.       I then registered a post-update plugin with message name‘DistributeCampaignActivity’ and Primary Entity: CampaignActivity10.   This time, when I clicked on the ‘DistributeCampaignActivity’ button for a Campaign, I was able to debug the plugin and find out that it was creating a record of type BulkOperationID11.   Naturally, I checked and found that there were 2 tables:  BulkOperation andBulkOperationLog and an entry was made into these tables ONLY when the record was of type “Distribute” or “QuickCampaign“.
12.   Finally, I was able to arrive at the below query which tells me if an account is a part of a ‘DistributeCampaignActivity’ or a QuickCampaign created in the last 7 days based on the account GUID: 
select COUNT(1) 
from FilteredBulkOperation FBO, FilteredBulkOperationLog FLOG 
where FBO.activityid=FLOG.bulkoperationid 
and FBO.actualend >= GETDATE()-7 and actualend<= GETDATE()
and FLOG.regardingobjectid ='20C7A5F8-AD02-DE11-83DE-0003FFE51F61'  /*–The Account GUID–*/
Thats it! :)

No comments:

Post a Comment