hi All,
I wrote below code to Import customer account form excel to d365fo
Using System.IO; Using OfficeOpenXml; Using OfficeOpenXml.ExcelPackage; Using OfficeOpenXml.ExcelRange; class ARP_ExcelImport { ////// Runs the class with the specified arguments. /// /// The specified arguments. public static void main(Args _args) { // Part 1 System.IO.Stream stream; CustTable custTable; AccountNum accountNum; ExcelSpreadsheetName sheet; FileUploadBuild fileUpload,fileUploadBuild; DialogGroup dialogUploadGroup; FormBuildControl formBuildControl; Dialog dialog = new Dialog("Excel Import"); dialogUploadGroup = dialog.addGroup("Select Excel File"); formBuildControl = dialog.formBuildDesign().control(dialogUploadGroup.name()); fileUploadBuild = formBuildControl.addControlEx(classStr(fileUpload),"UploadExcel"); fileUploadBuild.style(FileUploadStyle::MinimalWithFilename); fileUploadBuild.fileTypesAccepted(".xlsx"); if(dialog.run() && dialog.closedOk()) { FileUpload fileUploadControl=dialog.formRun().control(dialog.formRun().controlId("Upload")); FileUploadTemporaryStorageResult fileUploadResult = file::GetFileFromUser(classStr(FileUploadTemporaryStorageStrategy)); // end of Part 1 // Part 2 if(fileUploadResult!= null && fileUploadResult.getUploadStatus()) { stream=fileUploadResult.openResult(); using(ExcelPackage package= new ExcelPackage(stream)) { int rowCount, i; package.Load(stream); ExcelWorksheet worksheet= package.get_workbook().get_worksheets().get_Item(1); OfficeOpenXml.ExcelRange range=worksheet.Cells; rowCount = worksheet.Dimension.End.Row - worksheet.Dimension.Start.Row 1; try { for(i = 2; i <= rowCount; i ) { Info(range.get_Item(i,1).Value); accountNum = range.get_Item(i,1).Value; custTable.AccountNum = accountNum; custTable.insert(); } info("Data inserted succesfully"); } catch (Exception::Error) { ttsabort; throw error("error here"); } }// end using }// end if // end of Part 2 }// end if }// end if }
But it inserted the data in to DAT instead of USMF.
Kindly let me know why this happening? I like to insert in USMF
Pls give me more shed on this.
thanks!
Whenever you are running some custom code through a runnable job and you need to run that in particular company, you should set the company name in project properties. Else you should explicitly define that in code.
Thanks Girish, yes It was empty. I changed to USMF
Hi,
If you are running this class from the project check which company is given in the company under project property.
May be its empty, if its empty then it will be defaulted to DAT company.
Change that to Usmf and check.
Thanks,
Girish S.
Cust Table - SaveDataPerCompany set to Yes
I have ran that runnable class it showing DAT
is it the reason?
André Arnaud de Cal...
291,965
Super User 2025 Season 1
Martin Dráb
230,836
Most Valuable Professional
nmaenpaa
101,156