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

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Answered

data is inserted in to DAT insetad of USMF

(0) ShareShare
ReportReport
Posted on by 30

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!

I have the same question (0)
  • @rp@n Profile Picture
    30 on at
    RE: data is inserted in to DAT insetad of USMF

    I have ran that runnable class it showing DAT

    pastedimage1680450752945v1.png

    is it the reason?

  • @rp@n Profile Picture
    30 on at
    RE: data is inserted in to DAT insetad of USMF

    Cust Table -  SaveDataPerCompany set to Yes

    pastedimage1680451085319v1.png

  • Verified answer
    GirishS Profile Picture
    27,825 Moderator on at
    RE: data is inserted in to DAT insetad of 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.

  • @rp@n Profile Picture
    30 on at
    RE: data is inserted in to DAT insetad of USMF

    Thanks Girish, yes It was empty. I changed to USMF

  • Suggested answer
    Bharani Preetham Peraka Profile Picture
    3,634 Moderator on at
    RE: data is inserted in to DAT insetad of USMF

    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.

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…

Pallavi Phade – Community Spotlight

We are honored to recognize Pallavi Phade 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... 701 Super User 2025 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 588 Most Valuable Professional

#3
Sumit Singh Profile Picture

Sumit Singh 544

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans