web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Suggested Answer

SSRS Reports - Prefiltering for Dynamics 365

(0) ShareShare
ReportReport
Posted on by 184

Hi,

I have developed an SSRS report using Azure SQL database for Dynamics 365. But for some reason filters do not work. I want the report to run only on selected Account. But the report shows under "Run on all records". 

I created a view called FilteredAccount in azure db and my filter query is as shown below: 

SELECT name 
FROM FilteredAccount AS CRMAF_FilteredAccount


I believe adding alias with prefix CRMAF_ to the filtered view name should enable pre-filtering for SQL database. Not sure why this is not working. 

I tried filter options with Fetch XML and it works. Since it is a complex report, I am using Azure SQL db over Fetch XML.

Cheers

Deeksha



I have the same question (0)
  • Suggested answer
    Wahaj Rashid Profile Picture
    11,321 on at

    Hi,

    Thank you for your query.

    FilteredAccount view already exists in the Dynamics 365 database, do you have your own custom database? If yes, I am not sure if pre-filtering works on the custom views.

    If you are using pre-filtering on the out-of-the-box FilteredAccount view, in the report settings choose only to display in Forms for related record types:

    pastedimage1613543943340v1.png

    This way, you can only run the report from the form and data will be filtered based on the current record. When you select List for related record types it will show Run on all records.

  • handedee Profile Picture
    184 on at

    Hi Wahaj,

    Thanks for getting back.

    We are using Dynamics 365 Online. We do not have access to its database. We are using Data Export Service to sync the database tables to Azure SQL db. But with Data Export, I can only export entities (i.e., tables only) and not views. So I created a filtered view in Azure db.

    And yes, I have selected Display In Forms for related record types in report settings.

    Cheers

    Deeksha

  • Suggested answer
    Wahaj Rashid Profile Picture
    11,321 on at

    Hi,

    As far as I know, pre-filtering won't work on custom views/database.

    You can pass SSRS parameters to filter the data in your report.

    For example, if you need to dhow data related to current record, you can try following steps:

    • Create hidden parameter in SSRS report, e.g. @AccountID (String).
    • Add a ribbon button to run the report, call a JavaScript action (button command) and pass primaryControl parameter.
    • Get the data to be passed to report, here is the code to launch the report.

    var report_account_en = JSON.parse('{"reportId":"{report-guid}", "reportName":"Account Sample Report"}');
    
    // OnClick: on the ribbon button
    function report_clicked(primaryControl) {
    
        var formContext = primaryControl.getFormContext();
    
        var accountNo = formContext.getAttribute("accountnumber").getValue(); 
    
        if (accountNo == null || accountNo == "") {
            
            alert("Cannot get Account Number.");
    
        } else {
    
            
            // Please notep, @AccountId after p: is the SSRS parameter name.
            openReport(primaryControl, report_account_en.reportId, report_account_en.reportName, "p:@AccoountID="   accountNo);
        }
    
        
    }
    
    // Utility Function to open report window
    function openReport (primaryControl, reportId, reportName, params) {
    
        var formContext = primaryControl;
        var globalContext = Xrm.Utility.getGlobalContext(); 
    
        var urlOptions = { height: 800, width: 800 };
    	
        var entityType = encodeURIComponent("1");
        var entityId = encodeURIComponent(formContext.data.entity.getId());
        
        var reportGuid = encodeURIComponent(reportId); // Include curly brackets 
        var reportName = encodeURIComponent(reportName);
        
        //var parameters = encodeURIComponent(params);
    
        var serverUrl = globalContext.getClientUrl();
        var reportUrl = serverUrl   "/crmreports/viewer/viewer.aspx?action=run&context=records&helpID="   
    		reportName   "&id="   reportGuid   "&records="   
            ""   entityId   "&recordstype="   entityType  
            "&"   params;
        
        Xrm.Navigation.openUrl(reportUrl, urlOptions);
    }

    This is just an example, you can pass multiple parameters as well.

    Please note, you have to upload the report in the Dynamics 365 and use it's GUID to launch the report.

    Look into following blog for more details:

    https://community.dynamics.com/365/b/dynamics365enterprisecloudfronts/posts/open-report-from-custom-ribbon-button-on-entity-form

  • handedee Profile Picture
    184 on at

    Thanks Wahaj. I will try this and get back. At least now I know that prefiltering doesn't work on Custom views/db

    Cheers

    Deeksha

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Tom_Gioielli Profile Picture

Tom_Gioielli 137 Super User 2025 Season 2

#2
#ManoVerse Profile Picture

#ManoVerse 57

#3
Jimmy Passeti Profile Picture

Jimmy Passeti 50 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans