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, ...
Answered

Error while importing data from excel to some customized field of Sales Table error is"Field Sare order must be filled in"

(0) ShareShare
ReportReport
Posted on by 3,110

Errorwhileimportingdata.png

Hi Experts,

I wanted to import data to some customized fields to the Sales Table. Basically, I have added 6 fields new to sales table and tried to import data to these new fields from the excel sheet using X++ code. please check the above image with an error.

Best Regards,

Shabir 

I have the same question (0)
  • Suggested answer
    Gunjan Bhattachayya Profile Picture
    35,423 on at

    Hi Shabir,

    Are you importing data into for the additional fields into existing SalesTable records or are you importing new data into SalesTable? From the error it looks like the field SalesId is not being populated.

    You can share your code so that we can take a look and try to figure out the issue.

  • Gunjan Bhattachayya Profile Picture
    35,423 on at

    Hi Shabir,

    Were you able to resolve this issue? If yes, please mark the answer as verified.

  • Shabir Ahmad Profile Picture
    3,110 on at

    Hi Gunjan Bhattacharyya,

    I am importing data for new fields which i added to Sales table these are 6 fields added by me to Sales table. I am importing it from excel sheet.Still the issue is not resolved

    Best Regards,

    Shabir Ahmad

  • Gunjan Bhattachayya Profile Picture
    35,423 on at

    Hi Shabir,

    Can you share your code (which is throwing the error)?

  • Shabir Ahmad Profile Picture
    3,110 on at

    static void Esh_ReadExcel(Args _args)
    {
    
    SysExcelApplication application;
    SysExcelWorkbooks workbooks;
    SysExcelWorkbook workbook;
    SysExcelWorksheets worksheets;
    SysExcelWorksheet worksheet;
    SysExcelCells cells;
    COMVariantType type;
    
    int row=1;
    //Str Emp_Id,Emp_Name,Emp_Profile;
    FileName filename;
    SalesTable esh_ExcelUpload; //table buffer
        BRANCH branch;
        Target target;
        SALESMENNAME salesmenname;
        SMID smid;
        TgtCategory tgtcategory;
        TgtCatID tgtcatid;
        Channel channel;
    
    ;
    application = SysExcelApplication::construct();
    workbooks = application.workbooks();
    
    //specify the file path that you want to read
    filename = "C:\\TargetExcel.xlsx";
    
    try
    {
        workbooks.open(filename);
    }
    catch (Exception::Error)
    {
        throw error("File cannot be opened.");
    }
    
    workbook = workbooks.item(1);
    worksheets = workbook.worksheets();
    worksheet = worksheets.itemFromNum(1);
    cells = worksheet.cells();
    
    do
    {
        //read data from Excel
        row  ;
       // Emp_Id = cells.item(row, 1).value().bStr();
       // Emp_Name = cells.item(row, 2).value().bStr();
        //Emp_Profile = cells.item(row, 3).value().bStr();
        branch = cells.item(row,1).value().bStr ();
        target =  any2real(cells.item(row,2).value().toString());
        smid = cells.item(row,3).value().bStr ();
        channel = cells.item(row,4).value().bStr ();
        tgtcategory = cells.item(row,5).value().bStr ();
       tgtcatid = cells.item(row,6).value().bStr ();
        salesmenname = cells.item(row,6).value().bStr ();
       // info(strfmt('%1 - %2', Emp_Id, Emp_Name,Emp_Profile));
    
    
        type = cells.item(row 1, 1).value().variantType();
    
        //insert data into table
        esh_ExcelUpload.clear();
        esh_ExcelUpload.BRANCH      = branch;
        esh_ExcelUpload.Target    = target;
        esh_ExcelUpload.SALESMENNAME = salesmenname;
        esh_ExcelUpload.SMID      = smid;
        esh_ExcelUpload.TgtCategory    = tgtcategory;
        esh_ExcelUpload.TgtCatID = tgtcatid;
        esh_ExcelUpload.insert();
    }
    
    while (type != COMVariantType::VT_EMPTY);
    application.quit();
    }

    Please check the code 

  • Gunjan Bhattachayya Profile Picture
    35,423 on at

    Hi Shabir,

    You are inserting into SalesTable without setting SalesId and the other mandatory fields. That's why you are getting the error. Do you have the values for customer account etc. saved in the excel file you are trying to upload?

  • Verified answer
    Shabir Ahmad Profile Picture
    3,110 on at

    Hi Gunjan Bhattacharyya,

    I import data using excel-Add-In function very easily because of the short of time developing report. But i will next time try to import using x++ code as well thanks a lot.

    Best Regards,

    Shabir  

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
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 429 Most Valuable Professional

#3
BillurSamdancioglu Profile Picture

BillurSamdancioglu 239 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans