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;   ...

X++ code to create Direct Delivery Purchase order in D365FO

 X++ code to create Direct Delivery Purchase order in D365FO

class DirectDeliveryPO

{

/// <summary>

/// Runs the class with the specified arguments.

/// </summary>

/// <param name = “_args”>The specified arguments.</param>

public static void main(Args _args)

{

PurchAutoCreate purchAutoCreate;

PurchCreateFromSalesOrder purchCreateFromSalesOrder;

TmpPurchLinePrice tmpPurchLinePrice;

SalesTable salesTable;

SalesLine salesLine;

InventTable inventTable;

VendAccount prevVendAccount;

LineNum lineNum = 0;

SalesId salesId = ‘SO000081’;

str curCompany = curExt();

 

try

{

ttsbegin;

 

while select salesLine

order by inventTable.PrimaryVendorId

where salesLine.SalesId == salesId

join inventTable

where inventTable.ItemId == salesLine.ItemId

{

if (prevVendAccount && prevVendAccount != inventTable.PrimaryVendorId)

{

purchAutoCreate = PurchAutoCreate::construct(tmpPurchLinePrice, purchCreateFromSalesOrder);

purchAutoCreate.create();

delete_from tmpPurchLinePrice;

lineNum = 0;

}

 

salesTable = salesLine.salesTable();

purchCreateFromSalesOrder = PurchCreateFromSalesOrder::construct();

purchCreateFromSalesOrder.parmCallerRecord(salesTable);

purchCreateFromSalesOrder.parmTransferAddress(true);

purchCreateFromSalesOrder.parmSalesTable(salesTable);

purchCreateFromSalesOrder.parmSalesLine(salesLine);

 

tmpPurchLinePrice.clear();

lineNum += 1;

tmpPurchLinePrice.SalesId = salesLine.SalesId;

tmpPurchLinePrice.LineNum = lineNum;

tmpPurchLinePrice.SalesLineRefRecId = salesLine.RecId;

tmpPurchLinePrice.AccountNum = inventTable.PrimaryVendorId;

tmpPurchLinePrice.ItemId = salesLine.ItemId;

tmpPurchLinePrice.InventDimId = salesLine.InventDimId;

tmpPurchLinePrice.Included = NoYes::Yes;

tmpPurchLinePrice.PurchQty = salesLine.SalesQty;

tmpPurchLinePrice.QtyOrdered = salesLine.QtyOrdered;

tmpPurchLinePrice.PurchUnit = salesLine.SalesUnit;

tmpPurchLinePrice.LineAmount = salesLine.LineAmount;

tmpPurchLinePrice.lineDisc = salesLine.LineDisc;

tmpPurchLinePrice.LinePercent = salesLine.LinePercent;

tmpPurchLinePrice.MultiLineDisc = salesLine.MultiLnDisc;

tmpPurchLinePrice.MultiLinePercent = salesLine.MultiLnPercent;

tmpPurchLinePrice.Price = salesLine.PriceUnit;

tmpPurchLinePrice.CurrencyCode = salesLine.CurrencyCode;

tmpPurchLinePrice.Markup = salesLine.SalesMarkup;

tmpPurchLinePrice.insert();

 

prevVendAccount = tmpPurchLinePrice.AccountNum;

}

 

if (prevVendAccount)

{

purchAutoCreate = PurchAutoCreate::construct(tmpPurchLinePrice, purchCreateFromSalesOrder);

purchAutoCreate.create();

}

 

ttscommit;

Info(‘Direct Delivery PO Created’);

}

catch (Exception::Error)

{

 

ttsabort;

Info(‘Direct Delivery PO Failed’);

}

}

 

}

Comments

Popular posts from this blog

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

Passing Args from one Form to another Form in dynamics AX

CREATE AND POSTING PURCHASE ORDER THROUGH X++ DYNAMICS AX