In this post, I will explain how to use data methods in Reports. We will use the same Report model and report that we created in Building a Simple Report–Precision Design.
In AX 2009, AX SSRS had good use of these data methods. But with much better integration, and Reporting framework in AX improving, Data Methods in AX SSRS are reduced to minimal use.
Also the reason is that MS is soon going to do away with .Net Business Connector from next version hence the usage of data methods for many things will be redundant. What I have also noticed is the data methods have return type only as System.String and you will not be able to change this return type. This means, data methods can only return strings.
What I will try and demonstrate here is how to add links in AX reports (to open the corresponding forms).
To achieve this first we will add the reference to SRSDrillThroughCommon project. Do the following:
- Open the SKL_SampleReportProject (refer to link above)
- In Application Explorer, right-click Visual Studio Projects > C Sharp Projects > SRSDrillThroughCommon and then click Edit. This adds the SRSDrillThroughCommon project to our current solution
- Open the report SKL_SampleReportPrecision project
- Right click on the Data Methods node and create a new DataMethod. Name it CustDrillDown
- You will also notice that a Business Logic Project is automatically added
- In Solution Explorer, right-click the business logic project and then click Add Reference
- Go to “Projects” tab and select “SRSDrillThroughCommon” and click Ok
- Double click the data method this opens the Code editor
- Add this line of code the declaration
using Microsoft.Dynamics.AX.Application.Reports;
- Your code editor should be like this
using System;
using System.Collections.Generic;
using System.Security.Permissions;
using System.Data;
using Microsoft.Dynamics.Framework.Reports;
using Microsoft.Dynamics.AX.Application.Reports;
public partial class SKL_SampleReportPrecision
{
[DataMethod(), PermissionSet(SecurityAction.Assert, Name = “FullTrust”)]
public static string CustDrillDown(string reportContext, string custAccount)
{
return DrillThroughCommonHelper.ToCustomerForm(reportContext, custAccount);
}
}
- Right click on Precision Design and open the designer
- Select the AccountNum text box, underline the text and set font color to Blue
- Now right click on this text box and select “Text Box Properties…”, Switch to Tab “Action”
- Select option “Go to URL” and click button “fx”
- Set Expression “=CustDrillDown(Parameters!AX_ReportContext.Value, Fields!AccountNum.Value)”
- Click Ok
- Save report, go to AX, deploy the report and run it. You should see following
- Click on the link and the customer form opens up
Hi Summit after adding data method under ACTION——GO TO URL, when i am trying to open report its showing WARNING:URLs in report may only use http://,https://, help me out to resolve this issue
LikeLike
For what entity are you trying to hyperlink? Is it customers?
LikeLike
Yes sumit for customer only,in my data method i am returning
return DrillthroughHelper.GenerateLinkToAXMenuItem(reportContext, “CustTable”, Microsoft.Dynamics.Framework.Reports.MenuItemType.Display);
And in action—GO TO URL–expression is =”DataMethod1(Parameters!AX_ReportContext.Value,Fields!AccountNum.Value)” given
WARNING:URLs in report may only use http://,https://, help me out to resolve this issue
LikeLike
First of all let me check this method. But if you wish to connect to Customers form, try using
return DrillThroughCommonHelper.ToCustomerForm(reportContext, custAccount);
LikeLike
Hi Sumit,
In the above blog, the statement “Right click on the Data Methods node and create a new DataMethod. Name it CustDrillDown” and then in the next step “You will also notice that a Business Logic Project is automatically added”. But I have tried these both steps and the Business Logic project will not be automatically added. once we double click on the “CustDrillDown” method, then only it will get added in the solution.
Regards
Anuj
LikeLike
Yes it is added when you double click on the method and go to Code Behind.
LikeLike
Reblogged this on Microsoft Dynamics Kanha Ax Blog for Solution .
LikeLike
great
LikeLike
Do we have to add any references to use data methods in expression
LikeLike