Monday, August 31, 2009

CRM Pre-Filtering:

CRM Pre-Filtering:

To enable the pre filtering in the report just we need to add an alias for the filtered views which starts with “CRMAF_”. A query such as “Select name from FilteredAccount” can simply be changed to “Select name from FilteredAccount as CRMAF_Account”. Aliasing the Filtered View with a prefix of CRMAF_ will allow CRM to recognize that you would like to enable this entity for pre-filtering.


When you enable the CRM Pre-filtering functionality using the CRMAF_ method, CRM will take a query such as the following and modify it when it is uploaded into CRM:
This is the sample query:-


SELECT name, accountnumber
FROM FilteredAccount as CRMAF_Account

Becomes:
SELECT name, accountnumber
FROM (@P1) as CRMAF_Account

Then CRM will pass a query to the P1 parameter depending on how the report is being filtered. For example: when we run the report from the Reports area, the Pre-filtering functionality show all Accounts that are Active, and the resulting query would be something like:

SELECT name, accountnumber
FROM (select FilteredAccount.* from FilteredAccount where statecode = 0) as CRMAF_Account


If we are running the same report within a specific Account, the resulting query would be something like:

SELECT name, accountnumber
FROM (select FilteredAccount.* from FilteredAccount where AccountId = ‘’) as CRMAF_Account

If we are running the same report for a list of Accounts (suppose 3 accounts are selected from a view), the resulting query would be something like:

SELECT name, accountnumber
FROM (select FilteredAccount.* from FilteredAccount where AccountId in (’<1staccountid>’, ‘<2ndaccountid>’, ‘<3rdaccountid>’) as CRMAF_Account

No comments: