How to call a report and a report’s menuitem from X++

To call a report, use this code for example, if you need to call a report when clicking on a button :
void clicked()
{
Args args = new args();
ReportRun reportRun;
;
args.name(reportstr(PurchRequisitionDetails));
reportRun = classFactory.reportRunClass(args);
reportRun.init();
reportrun.run();

super();
}

To call a report’s menuitem , use this one :

MenuFunction menuFunction;
;
menuFunction = new MenuFunction(reportStr(Cust), MenuItemType::Output);
menuFunction.create();
menuFunction.run();