我在Visual Studio 2008中创建了一个基于SQL的报告,并将其上传到CRM。我表示你只能在“相关记录类型的表单”上运行它。我认为这会为您当前的记录生成1个报告。
事实并非如此。它为特定实体(订单)的每条记录生成一份报告,报告中每页有1条记录。
我知道我必须使用Data-Prefiltering(自动或特定?),但是没有好的在线示例,而且stackoverflow上甚至有一个线程,但我jsut无法弄明白。
链接到主题:CRMAF Filtering in CRM 2011
SELECT FilteredSalesOrder.customerid AS x1, FilteredAccount.accountid AS x2, FilteredSalesOrderDetail.salesorderid AS x3, FilteredSystemUser.systemuserid AS x4,
FilteredProduct.productid AS x5, FilteredAccount.address1_city, FilteredAccount.address1_line1, FilteredAccount.address1_postalcode, FilteredAccount.name AS AccountName,
FilteredSalesOrder.ordernumber, FilteredSalesOrderDetail.quantity, FilteredSystemUser.fullname, FilteredProduct.fmcg_erpreference, FilteredProduct.name AS ProductName
FROM FilteredSalesOrder INNER JOIN FilteredAccount
ON FilteredSalesOrder.customerid = FilteredAccount.accountid INNER JOIN FilteredSalesOrderDetail
ON FilteredSalesOrderDetail.salesorderid = FilteredSalesOrder.salesorderid INNER JOIN FilteredProduct
ON FilteredProduct.productid = FilteredSalesOrderDetail.productid INNER JOIN FilteredSystemUser
ON FilteredSystemUser.systemuserid = FilteredSalesOrder.ownerid
仅预过滤数据以使用当前订单:
FROM FilteredSalesOrder AS CRMAF_FilteredSalesOrder INNER JOIN FilteredAccount
编辑:
这是我使用FilteredSalesOrder上的CRMAF_的全新SQL。但唉它不起作用。它仍然只给我机会对所有记录运行它,从而生成所有存在的销售人员(幸运的是没有那么多)。
SELECT CRMAF_FilteredSalesOrder.customerid AS x1, CustomerAccount.accountid AS x2,
FilteredSalesOrderDetail.salesorderid AS x3, FilteredSystemUser.systemuserid AS x4,
FilteredProduct.productid AS x5,CRMAF_FilteredSalesOrder.fmcg_supplierid as x6,
CustomerAccount.address1_city as customerCity, CustomerAccount.address1_line1 as
customerStreet1, CustomerAccount.address1_postalcode as customerPostalCode,
CustomerAccount.name AS CustomerAccountName, CRMAF_FilteredSalesOrder.ordernumber,
FilteredSalesOrderDetail.quantity, FilteredSystemUser.fullname,
FilteredProduct.fmcg_erpreference, FilteredProduct.name AS ProductName,
SupplierAccount.name as supplierAccountName, SupplierAccount.address1_city AS
supplierCity,SupplierAccount.address1_line1 as supplierStreet1,
SupplierAccount.address1_postalcode as supplierPostalCode,
CRMAF_FilteredSalesOrder.requestdeliveryby, CRMAF_FilteredSalesOrder.createdon
FROM FilteredSalesOrder AS CRMAF_FilteredSalesOrder INNER JOIN FilteredAccount AS CustomerAccount
ON CRMAF_FilteredSalesOrder.customerid = CustomerAccount.accountid INNER JOIN FilteredSalesOrderDetail
ON FilteredSalesOrderDetail.salesorderid = CRMAF_FilteredSalesOrder.salesorderid INNER JOIN FilteredProduct
ON FilteredProduct.productid = FilteredSalesOrderDetail.productid INNER JOIN FilteredSystemUser
ON FilteredSystemUser.systemuserid = CRMAF_FilteredSalesOrder.ownerid INNER JOIN FilteredAccount AS SupplierAccount
ON CRMAF_FilteredSalesOrder.fmcg_supplierid = SupplierAccount.accountid
解决方案:已删除报告并重新部署。
答案 0 :(得分:4)
请参阅MSDN上的Sample: Make a Report Context-Sensitive。
您只需要过滤当前 SalesOrder。
CRM 2011中有关自动预过滤的文档很少,但我认为CRM 2011和CRM 4之间没有太大变化。因此,请参阅MSDN上的Using Filters in a Report有关CRM 4中的SSRS报告的信息。更好的解释。
我经常在报告中使用的是像CRM_FilteredSalesOrder
这样的参数,结合SQL查询,如下所示:
EXEC('
SELECT FSO.*
FROM (' + @CRM_FilteredSalesOrder + ') AS FSO
')
它与自动预过滤的原理相同,但现在您可以控制预过滤器的插入位置。另请注意,SSRS报告中的单个查询中不能多次使用自动预过滤器。
编辑:好的,让我直接使用你的例子:
EXEC('
SELECT
FSO.customerid AS x1,
FilteredAccount.accountid AS x2,
FilteredSalesOrderDetail.salesorderid AS x3,
FilteredSystemUser.systemuserid AS x4,
FilteredProduct.productid AS x5,
FilteredAccount.address1_city,
FilteredAccount.address1_line1,
FilteredAccount.address1_postalcode,
FilteredAccount.name AS AccountName,
FSO.ordernumber,
FilteredSalesOrderDetail.quantity,
FilteredSystemUser.fullname,
FilteredProduct.fmcg_erpreference,
FilteredProduct.name AS ProductName
FROM (' + @CRM_FilteredSalesOrder + ') AS FSO
INNER JOIN FilteredAccount ON FSO.customerid = FilteredAccount.accountid
INNER JOIN FilteredSalesOrderDetail ON FilteredSalesOrderDetail.salesorderid = FSO.salesorderid
INNER JOIN FilteredProduct ON FilteredProduct.productid = FilteredSalesOrderDetail.productid
INNER JOIN FilteredSystemUser ON FilteredSystemUser.systemuserid = FSO.ownerid
')
如果您想了解CRM插入的内容,请将CRM_FilteredSalesOrder
参数放在报告的文本框中。当它出现在“相关记录类型的表单”时,它将是SELECT f0.* FROM FilteredSalesOrder AS f0 WHERE f0.salesorderid = '3641478b-5022-40fa-90c1-a4d407e8b99b'
形式的查询。这实际上是这个特定订单的子查询。这就是他们所谓的“预过滤”,你只需查询一个子查询。