Skip to main content



No record found.

Dynamics 365 Community / Forums / Finance forum / Import Utility for Sal...
Finance forum
Suggested answer

Import Utility for Sales order in X++

Posted on by 257
Hi Folks,
I have been working in the Import utility for sales order in excel format.. 
So could any one please help me to provide any sample code for the same..
Thanks in Advance!!
  • André Arnaud de Calavon Profile Picture
    André Arnaud de Cal... 287,696 Super User on at
    Import Utility for Sales order in X++
    Hi D365 Avatar,

    You are confusing me with your question, a particular reply on "creating Dynamics fields" and sharing some code where I don't see anything related to "Dynamics fields". Can you explain functionally what you need to achieve?
  • Suggested answer
    Navneeth Nagrajan Profile Picture
    Navneeth Nagrajan 1,339 on at
    Import Utility for Sales order in X++
    Hi D365FO Avatar,
    As Martin recommended, the best approach is to use Data Management. Would suggest only validating custom fields (if any) through custom code at the extension class rather than building an import utility etc. 
    In Data Management you have the option to select the source as Excel or csv and run it on entities like SalesOrderHeaderV2Entity and SalesOrderLineV2Entity. 
  • D365FO Avatar Profile Picture
    D365FO Avatar 257 on at
    Import Utility for Sales order in X++
    Hi folks,
    I'm facing an issue in while Generate Picking List, the item line is not coming in the form.
    Although I'm calling the below code but I'm not understanding the logic used for 
    SalesLine.createLine() method.

    NumberSeq numberSeq = NumberSeq::newGetNum(SalesParameters::numRefSalesId());
                                    salesid = numberSeq.num();
                                    InventLocationId        warehouse          = range.get_item(row, 14).value;
                                    str id = salesid;
                                    salesTable.SalesId                          = salesid;
                                    salesTable.CustAccount                      = range.get_Item(row, 22).value;
                                    salesTable.CurrencyCode                     = range.get_item(row, 33).value;
                                    salesTable.ReceiptDateRequested             = range.get_item(row, 1).value;
                                    salesTable.DeliveryName                     = range.get_item(row, 3).value;
                                    salesTable.DeliveryPostalAddress            = range.get_item(row, 4).value;
                                    salesTable.ShippingDateRequested            = range.get_item(row, 2).value;
                                    salesTable.ShippingDateConfirmed            = range.get_item(row, 5).value;
                                    salesTable.ReceiptDateConfirmed             = range.get_item(row, 6).value;
                                    salesTable.InventSiteId                     = range.get_item(row, 13).value;
                                    salesTable.SalesName                        = range.get_item(row, 23).value;
                                    salestable.InvoiceAccount                   = range.get_item(row, 25).value;
                                    salesTable.CustomerRef                      = range.get_item(row, 26).value;
                                    salesTable.CustomerRefDate                  = range.get_item(row, 27).value;
                                    salesTable.TransporterName                  = range.get_item(row, 31).value;
                                    salesTable.DlvMode                          = range.get_item(row, 32).value;
                                    salesTable.Freight                          = range.get_item(row, 36).value;
                                    salesTable.VehicleNumber                    = range.get_item(row, 37).value;
                                    salestable.TransportDate                    = range.get_item(row, 38).value;
                                    salesTable.BankName                         = range.get_item(row, 39).value;
                                    salesTable.modifiedField(fieldNum(salesTable, InventSiteId));
                                    salesTable.modifiedField(fieldNum(salesTable, InventLocationId));
                                    salesTable.LanguageId                       = Range.get_Item(row, 44).value;
                                    select custTable
                                    where  custTable.AccountNum == range.get_Item(row, 22).value;;
                                    salesTable.CustGroup                        = custTable.CustGroup;
                                    if (InventLocation::find(warehouse).InventLocationId)
                                        salesTable.InventSiteId                 = InventLocation::find(warehouse).InventSiteId;
                                        salesTable.InventLocationId             = InventLocation::find(warehouse).InventLocationId;
                                    select forupdate salesTable
                                    where salesTable.SalesId == id;

                                    salesTable.DlvMode                      = dlvmode;
                                    salesLine.SalesId                       = salesid;
                                    salesLine.ItemId                        = range.get_item(row, 7).value;
                                    salesLine.Name                          = InventTable::find(itemid).NameAlias;
                                    salesLine.SalesQty                      = range.get_item(row, 9).value;
                                    salesLine.RemainSalesPhysical           = salesLine.SalesQty;
                                    salesLine.SalesUnit                     = range.get_item(row, 10).value;
                                    salesLine.QtyOrdered                    = salesLine.salesPurchLineInterface().calculateQuantityOrdered(salesLine.SalesQty);
                                    salesLine.RemainInventPhysical          = salesLine.QtyOrdered;
                                    salesLine.SalesPrice                    = range.get_item(row, 11).value;
                                    salesLine.SalesDeliverNow               = range.get_item(row, 12).value;
                                    salesLine.LineDisc                      = range.get_item(row, 16).value;
                                    salesLine.LinePercent                   = range.get_item(row, 17).value;
                                    salesLine.DlvMode                       = range.get_item(row, 32).value;
                                    inventDim                               = salesLine.inventDim();
                                    InventDim.wMSLocationId                 = Range.get_Item(row, 15).value;
                                    InventDim.InventSiteId                  = salesLine.inventDim().InventSiteId;
                                    InventDim.InventLocationId              = salesLine.inventDim().InventLocationId;
                                    Saleslineinventdim                      = InventDim::findOrCreate(InventDim);
                                    salesLine.InventDimId                   = Saleslineinventdim.inventDimId;
                                    salesLine.SalesStatus                   = SalesStatus::Backorder;
                                    salesLine.LineAmount                    = salesLine.calcLineAmount(qty);
                                    salesLine.createLine(false, // validation
                                    false,                                                       // initFromSalesTable
                                    false,                                                       // initFromInventTableModule
                                    false,                                                       // calcInventQty
                                    true,                                                       // searchMarkup
                                    false,                                                       // searchPrice
                                    ItemReservation::Automatic,      // checkReservation
                                    false,                                                      // skipCreditLimitCheck
                                    false,                                                      // ignoreSalesTableInventDim
                                    true,                                                       // setLineNum
                                    false);                        // searchAgreementLine
                                    select forUpdate salesLine_IN
                                    where salesLine_IN.SalesLine == salesLine.RecId;
                                    if (salesLine_IN.RecId)
                                        salesLine_IN.AssessableValue_IN = salesLine.LineAmount ;
                                        salesLine_IN.AssessableValueTransactionCurrency =  salesLine.LineAmount ;
                                        salesLine_IN.SalesLine = salesLine.RecId;
                                        salesLine_IN.AssessableValue_IN = salesLine.LineAmount ;
                                        salesLine_IN.AssessableValueTransactionCurrency = salesLine.LineAmount ;
  • Bharani Preetham Peraka Profile Picture
    Bharani Preetham Pe... 3,526 Super User on at
    Import Utility for Sales order in X++
    If fields are not present in entity then you can add them. Can you give me more understanding behind?
  • Suggested answer
    Mohamed Amine Mahmoudi Profile Picture
    Mohamed Amine Mahmoudi 7,209 User Group Leader on at
    Import Utility for Sales order in X++
    If Data Management doesn't suit you, you can use RunBaseBatch or SysOperationFramework to import and process the data.
    Best regrds,
    Mohamed Amine MAHMOUDI
  • Martin Dráb Profile Picture
    Martin Dráb 225,490 Super User on at
    Import Utility for Sales order in X++
    Can you tell us more about the logic that you think can't be done in a data entity? Note that you can write X++ code in entities, therefore you can put any arbitrary logic there, while you don't have to reinvent a framework for data import.
  • D365FO Avatar Profile Picture
    D365FO Avatar 257 on at
    Import Utility for Sales order in X++
    The point is they want to import some dynamics fields in sales order form as well which is not present in the sales table which can't be possible through data entity so we need to create a class for this.
    So when user import the excel it should automatically create fields in the table which is present in the excel.
    So before that I need to create a simple import utility for sales order.
  • rajborad Profile Picture
    rajborad 238 on at
    Import Utility for Sales order in X++
    You can use the standard data entity for importing sales order headers and lines.
    Entities are: 
  • Martin Dráb Profile Picture
    Martin Dráb 225,490 Super User on at
    Import Utility for Sales order in X++
    Are you 100% sure that you can't use Data Management and you need to invest a lot of time to designing, developing, testing and maintaining a custom solution?

Helpful resources

Quick Links

Replay now available! Dynamics 365 Community Call (CRM Edition)

Catch up on the first D365 Community Call held on 7/10

Community Spotlight of the Month

Kudos to Saurav Dhyani!

Congratulations to the June Top 10 community leaders!

These stars go above and beyond . . .


André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 287,696 Super User

Martin Dráb Profile Picture

Martin Dráb 225,490 Super User

nmaenpaa Profile Picture

nmaenpaa 101,148


Featured topics

Product updates

Dynamics 365 release plans