Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8620961
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T06:42:27+00:00 2026-06-12T06:42:27+00:00

I made a SQL-based report in Visual Studio 2008 and uploaded it to the

  • 0

I made a SQL-based report in Visual Studio 2008 and uploaded it to the CRM. I indicated that you can only run it on “Forms for related record types”. I thought this would generate 1 report for the current record you are in.

This isn’t the case. It generates a report for each record of the specific entity (Order), 1 record per page in the report.

I know I have to use Data-Prefiltering (automatic or specific?), but there are no good examples online and there is even a thread here on stackoverflow but I jsut can’t figure it out.

Link to thread: 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

To pre-filter the data only to use the current Order:

  • Use CRMAF_ with only the SalesOrder Table, is that enough?

FROM FilteredSalesOrder AS CRMAF_FilteredSalesOrder INNER JOIN FilteredAccount

  • Use CRMAF_ with all the tables?

EDIT:

This is my new entire SQL where I used the CRMAF_ on FilteredSalesOrder. But alas it does not work. It still gives me only the opportunity to run it against all records, and thus generates all the Salesorders that exist (luckily there are not that many).

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

Solution: Deleted Report and redeployed it.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T06:42:28+00:00Added an answer on June 12, 2026 at 6:42 am

    See Sample: Make a Report Context-Sensitive on MSDN.

    You only need to filter on the current SalesOrder.

    The documentation on automatic prefiltering in CRM 2011 is sparse, however, I think it hasn’t changed much between CRM 2011 and CRM 4. So please refer to Using Filters in a Report on MSDN regarding SSRS reports in CRM 4 for a better explanation.

    What I often use in reports are parameters like CRM_FilteredSalesOrder combined with a SQL query like the following:

    EXEC('
        SELECT FSO.*
        FROM (' + @CRM_FilteredSalesOrder + ') AS FSO
    ')
    

    It is the same principle as automatic prefiltering, but now you control where the prefilter is inserted. Also remember that an automatic prefilter can’t be used more than once in a single query in an SSRS report.

    EDIT: OK, let me just literally use your example:

    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
    ')
    

    If you want to understand what the CRM inserts, put the CRM_FilteredSalesOrder parameter in a textbox on the report. It will be a query in the form SELECT f0.* FROM FilteredSalesOrder AS f0 WHERE f0.salesorderid = '3641478b-5022-40fa-90c1-a4d407e8b99b' when it’s on “Forms for related record types”. This is effectively a subquery for this one particular Order. That’s what they call “prefiltering”, you’ll just query a subquery.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In a windows Server 2008, using SQL server 2005, Visual Studio and SQL Server
I have this sql that is made by help of others. $sql = select
i have made columns in some of the tables encrypted in sql server 2008.
I need to run my application on network. The application is based on SQL
I made an application that generates reports based on data from a database. The
I have a very basic question about SQL server and Visual Studio 2010. I'm
Using Visual Studio 2010 and SQL management Studio, I have created a page by
ODI is mandatory at work but any changes made to SQL are stored internally
I made an .sdf file (SQL CE) from an XML file. When the file
I Made login (x) with sql authentication for mydatabase(Sharp) in sql2000.And I want to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.