How to Call X++ code inside an SSRS report

Create a data method like this

    [DataMethod(), AxSessionPermission(SecurityAction.Assert)]
    public static string getOnHand(string itemId, string inventBatchId)
        //gets a session
        var ax = Microsoft.Dynamics.Framework.Reports.SessionManager.GetSession();

        //creates an instance of the inventOnHand Class
        var onHand = ax.CreateAxaptaObject("InventOnHand");
        //calls method “ParmItemId” and passes in the value of ItemId supplied to the data method
        onHand.Call("ParmItemId", itemId);
        // conditionally filter based on inventBatchId
        if(inventBatchId != "")
            onHand.Call("ParmBatchId", inventBatchId);
        //call “availPhysical()” on your InventOnHand object and capture the value
        var availPhysical = onHand.Call("availPhysical");

        //return it as a string to match the data Methods cast type
        return availPhysical.ToString();


The equivilent AX code is …

InventOnHand OnHand;
Qty availPhysical;

onHand = new InventOnHand();
if(InventBatchId != “”)
availPhysical = onHand.availPhysical();
return availPhysical;