Posts

Showing posts with the label Exporting and Import

Create an excel file and send it through Email in D365 using X++ code

Image
             This post is about creating an excel file using X++ and attach it as an Email(office 365 SMTP) attachment without saving it in local file location.  SysMailerMessageBuilder          mailer  = new SysMailerMessageBuilder (); SysMailerSMTP                    smtp    = new SysMailerSMTP (); RowNumber                        row     = 1 ; RESPDCLogTable                   pDCLogTable1; System.IO. MemoryStream  memoryStream     = new  System.IO. MemoryStream (); mailer.setSubject(strFmt( "PDC posted batch status %1" ,sessionDate)); mailer.setFrom( SysUserInfo ::find().Email); mailer.setBody( 'Please find the PDC Status report.' ); mailer.addTo(' ToMailAddress ' );     using ( var package = new OfficeOpenXml. ExcelPackage (memoryStream))   {       var worksheets = package.get_Workbook().get_Worksheets();       var worksheet  = worksheets.Add( "PDC batch status" );       var cells      = worksheet.get_Cells();       var cell       = cel

Create movement journal through X++ code in D365FO(Import code)

class DAL_MovementJournal {       public static void main( Args _args)     {

Importing data from Excel through X++ code

  Sometimes we need to import data from  Excel to  Microsoft Dynamics 365 form  using x++ code. Through this post can see how to import a data from  excel to  form Public static class ImportLeaveRequestLine {     public static void main( Args _args)     {         System.IO. Stream stream;         LeaveRequestHeader LeaveRequestHeader = _args.record();         LeaveRequestLine    LeaveRequestLine;         ExcelSpreadsheetName sheeet;         FileUploadBuild fileUpload;         DialogGroup dlgUploadGroup;         FileUploadBuild fileUploadBuild;         FormBuildControl formBuildControl;         Dialog dialog = new Dialog ( "Import the leave details" );         ;         dlgUploadGroup = dialog.addGroup( "Select excel file" );         formBuildControl = dialog.formBuildDesign().control(dlgUploadGroup.name());         fileUploadBuild = formBuildControl.addControlEx( classstr ( FileUpload ), 'Upload' );   

Exporting data to Excel through X++ code

             Sometimes we need to export data from Microsoft Dynamics 365 to Excel using x++ code. Through this post can see how to export data from form to excel class SMJ_ExportData {     public static void main( Args args)     {         PurchParmLine   PurchParmLine,PurchParmLineSelect;         PurchParmLine = args.record();         DocuFileSaveResult saveResult = DocuFileSave ::promptForSaveLocation( "@ApplicationPlatform:Testingexcelexport ", "xlsx" , null , "Testing excel export" );         if (saveResult && saveResult.parmAction() != DocuFileSaveAction ::Cancel)         {             saveResult.parmOpenParameters( 'web=1' );             saveResult.parmOpenInNewWindow( false );             System.IO. Stream workbookStream = new System.IO. MemoryStream ();             System.IO. MemoryStream memoryStream = new System.IO. MemoryStream ();                    using ( var package = new Of