web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Suggested Answer

Import Utility for Sales order in X++

(1) ShareShare
ReportReport
Posted on by 670
 
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!!
I have the same question (0)
  • Martin Dráb Profile Picture
    237,990 Most Valuable Professional on at
    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?
  • Raj Borad Profile Picture
    1,434 on at
    You can use the standard data entity for importing sales order headers and lines.
    Entities are: 
    SalesOrderHeaderV2Entity
    SalesOrderLineV2Entity
     
     
  • D365FO Avatar Profile Picture
    670 on at
    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.
     
     
  • Martin Dráb Profile Picture
    237,990 Most Valuable Professional on at
    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.
  • Suggested answer
    Mohamed Amine Mahmoudi Profile Picture
    26,449 Super User 2025 Season 2 on at
    Hi, 
     
    If Data Management doesn't suit you, you can use RunBaseBatch or SysOperationFramework to import and process the data.
     
    Best regrds,
    Mohamed Amine MAHMOUDI
  • Bharani Preetham Peraka Profile Picture
    3,634 Moderator on at
    If fields are not present in entity then you can add them. Can you give me more understanding behind?
  • D365FO Avatar Profile Picture
    670 on at
     
    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.clear();
                                    salesTable.initValue(SalesType::Sales);
                                    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;
                                    salesTable.initFromCustTable();
     
                                    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;
                                    }
                                    salesTable.insert();
     
                                    select forupdate salesTable
                                    where salesTable.SalesId == id;

                                    salesTable.DlvMode                      = dlvmode;
                                    salesTable.update();                                
                                    salesLine.clear();
                                    salesLine.initValue(salesTable.SalesType);
                                    salesLine.initFromSalesTable(salesTable);
                                    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.setInventDimId(Saleslineinventdim.inventDimId,Saleslineinventdim);
                                    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
     
                                   salesLine.validateWrite();
     
                                    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.update();
                                    }
                                    else
                                    {
                                        salesLine_IN.clear();
                                        salesLine_IN.initValue();
                                        salesLine_IN.SalesLine = salesLine.RecId;
                                        salesLine_IN.AssessableValue_IN = salesLine.LineAmount ;
                                        salesLine_IN.AssessableValueTransactionCurrency = salesLine.LineAmount ;
                                        salesLine_IN.insert();
                                    }
     
  • Suggested answer
    Navneeth Nagrajan Profile Picture
    2,438 Super User 2025 Season 2 on at
    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. 
     
     
  • André Arnaud de Calavon Profile Picture
    301,200 Super User 2025 Season 2 on at
    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?

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Abhilash Warrier Profile Picture

Abhilash Warrier 669 Super User 2025 Season 2

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 471 Super User 2025 Season 2

#3
Martin Dráb Profile Picture

Martin Dráb 423 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans