[D365] Get list of Designs of SRS Report by code

Recently the requirement to list all designs of a SRSReport came up and the Metadata API is a good fit for the task to accomplish this with as less lines of code as possible.

The example below will add a static method to the standard class SrsReportHelper to have it available system-wide.

using Microsoft.Dynamics.AX.Metadata.MetaModel;
using System.Collections;

[ExtensionOf(classStr(SrsReportHelper))]
public final class SrsReportHelper_Extension
{
	public static List robsGetDesignsOfReport(SRSReportName _reportName)
    {
        List srsReportDesignsList = new List(Types::String);
        AxReport axReport = Microsoft.Dynamics.Ax.Xpp.MetadataSupport::GetReport(_reportName);
        // axReport.Designs will return a KeyedObjectCollection. Check it with ildasm.exe
        var designs = axReport.Designs;
        int noOfDesigns = designs.Count;
        for (int dIdx = 0; dIdx < noOfDesigns; dIdx++)
        {
            AxReportDesign design = designs.get_Item(dIdx);
            srsReportDesignsList.addEnd(design.Name);
        }
        
        return srsReportDesignsList;
    }

}

The using statement at the top is only comfort to be able to use the metadata interfaces like AxReport without the whole assembly name.

Usage

An example to consume the method:

TmpSrsReportDesignName tmpSrsReportDesignName;
ListEnumerator le = SrsReportHelper::robsGetDesignsOfReport(reportStr(SalesInvoice)).getEnumerator();

tmpSrsReportDesignName.clear();
tmpSrsReportDesignName.initValue();

while (le.moveNext())
{
    tmpSrsReportDesignName.DesignName = le.current();
    tmpSrsReportDesignName.insert();
}