Thursday, March 27, 2014

AX 2012: Running an AX query from C# data method in SSRS


  1. Create a new query in AX 2012 from the AOT.
  2. Open a SSRS report and create a new data method. 
  3. Replace the code with the following:
 [DataMethod(), PermissionSet(SecurityAction.Assert, Name = "FullTrust")]  
 public static string TestMethod()  
 {  
      IEnumerable dt = Microsoft.Dynamics.Framework.Reports.AxQuery.ExecuteQueryStream("SELECT * FROM EmplQuery");  
      IEnumerator e = dt.GetEnumerator();  
      if (e.MoveNext())  
           return e.Current.Field(1);  
      else  
           return "No results";  
 }  
Don't forget to rename the method to the one you created, replace "EmplQuery" with the name of your query, replace return type with your type and select the field that you want when returning. Let me know if you want an example of returning a specific field by its name.

No comments:

Post a Comment