Skip to main content

Notifications

Finance | Project Operations, Human Resources, ...
Answered

data is inserted in to DAT insetad of USMF

(0) ShareShare
ReportReport
Posted on by

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!

  • Suggested answer
    Bharani Preetham Peraka Profile Picture
    Bharani Preetham Pe... 3,587 Super User 2024 Season 1 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.

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

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

  • Verified answer
    GirishS Profile Picture
    GirishS 27,821 Super User 2024 Season 1 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
    @rp@n on at
    RE: data is inserted in to DAT insetad of USMF

    Cust Table -  SaveDataPerCompany set to Yes

    pastedimage1680451085319v1.png

  • @rp@n Profile Picture
    @rp@n 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?

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

Announcing Our 2025 Season 1 Super Users!

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

Announcing Forum Attachment Improvements!

We're excited to announce that attachments for replies in forums and improved…

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,965 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 230,836 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans