Skip to main content

Notifications

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

Import Utility for Sales order in X++

Posted on by 347
 
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... 290,445 Super User 2024 Season 2 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,347 Super User 2024 Season 2 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 347 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.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();
                                    }
     
  • Bharani Preetham Peraka Profile Picture
    Bharani Preetham Pe... 3,548 Moderator 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 9,292 Super User 2024 Season 2 on at
    Import Utility for Sales order in X++
    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
  • Martin Dráb Profile Picture
    Martin Dráb 228,334 Most Valuable Professional 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 347 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.
     
     
  • Raj Borad Profile Picture
    Raj Borad 369 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: 
    SalesOrderHeaderV2Entity
    SalesOrderLineV2Entity
     
     
  • Martin Dráb Profile Picture
    Martin Dráb 228,334 Most Valuable Professional 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?

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

Dynamics 365 Community Update – Sep 16th

Welcome to the next edition of the Community Platform Update. This is a weekly…

Announcing Our 2024 Season 2 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Dynamics 365 Community Newsletter - September 2024

Check out the latest community news

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 290,445 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 228,334 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans