How to Import Records from Excel Using X++ Code in D365FO

  How to Import Records from Excel Using X++ Code in D365FO   Include the below namespace in X++ code it will requires to import Excel. Using System.IO; Using OfficeOpenXml; Using OfficeOpenXml.ExcelPackage; Using OfficeOpenXml.ExcelRange;   In addition to the basic reference, include (Directory and DirectoryUpgrade Packages) X++ Code: Using System.IO; Using OfficeOpenXml; Using OfficeOpenXml.ExcelPackage; Using OfficeOpenXml.ExcelRange; class ReadExcel {   public static void main(Args _args)    {     Int id;     Str Name;      System.IO.Stream stream;       ExcelSpreadsheetName sheet;              FileUploadBuild fileUpload,fileUploadBuild;       DialogGroup dialogUploadGroup;       FormBuildControl formBuildControl;       Dialog dialog=new Dialog("Excel Import using dialog");       dialogUploadGroup=dialog.addGroup("@SYS54759");       formBuildControl=dialog.formBuildDesign().control(dialogUploadGroup.name());    

Passing the value from Form to Class using X++ in AX


First create a form  Test form with a table called Test table where we will have field(Name) over there and one grid in design and one button over there. 
Then create a new class and named it as TestClass
public static void main(Args args)
{
TestTable   testTable;

If(args.record().TableId == tablenum(TestTable))
{
testTable = args.record();
info(strFmt("%1", testTable.Name));
}
}
Create a new menu item named TestMenu with action type and assign the TestClass to that. 
Then write the click method of that button as 

void clicked()
{
    //super();

    MenuFunction    mf;
    args            args = new Args();
    ;


    args.record(TestTable);


    mf = new menufunction(identifierstr(TestMenu), MenuItemType::Action);
    mf.run(args);
}
now open the form and insert a record and click the button you will get output

Comments

Popular posts from this blog

D365 FO: REFRESH CALLER FORM DATA SOURCE FROM A CLASS X++

Customize SSRS report using extension in D365FO

CREATE AND POSTING PURCHASE ORDER THROUGH X++ DYNAMICS AX