Notifications
Announcements
No record found.
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
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.
Were you able to resolve this issue? If yes, please mark the answer as verified.
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
Shabir Ahmad
Can you share your code (which is throwing the error)?
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
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?
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.
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.
As AI tools become more common, we’re introducing a Responsible AI Use…
We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…
These are the community rock stars!
Stay up to date on forum activity by subscribing.
André Arnaud de Cal... 456 Super User 2025 Season 2
Martin Dráb 429 Most Valuable Professional
BillurSamdancioglu 239 Most Valuable Professional