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

In X++ multiple Record

(0) ShareShare
ReportReport
Posted on by 1,215

Hi guys,

i want to insert multiple record in import in excel below my code  not working multiple record. 

private void importStagingData()
    {
        int                             rowNo, counter;
        HcmWorker                       worker;
        str                             personId;
        SDSStagingTable                 toInsert;
        SelectableDataArea              da;
        OfficeOpenXml.ExcelRange        columnVal;
        OfficeOpenXml.ExcelRange        colValNum;
       
        rowNo=2;
        if (dialog.run() && dialog.closedOk())
        {
            FileUpload fileUploadControl     = dialog.formRun().control(dialog.formRun().controlId("Upload"));
            FileUploadTemporaryStorageResult fileUploadResult = fileUploadControl.getFileUploadResult();
        
            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;
                    for (i = 0; i<= rowCount; i  )
                    {
                        ttsBegin;
                        toInsert.clear();
                        toInsert.EMP                        = range.get_Item(i,1).Value;
                        toInsert.Person                     = range.get_Item(i,2).Value;
                        toInsert.EmplGroup                  = range.get_Item(i,3).Value;
                        toInsert.Nat                        = range.get_Item(i,4).Value;
                        toInsert.Gender                     = str2Int( range.get_Item(i,5).Value);
                        toInsert.Education                  = range.get_Item(i,6).Value;
                        toInsert.BloodType                  = str2Int(range.get_Item(i,7).Value);
                        toInsert.Religion                   = range.get_Item(i,8).Value;
                        toInsert.OldId                      = range.get_Item(i,9).Value;
                        toInsert.TransID                    = range.get_Item(i,10).Value;
                        toInsert.TransDate                  = str2Date(range.get_Item(i,11).Text, 123);
                        toInsert.AmountCur                  = any2Real(range.get_Item(i,12).Value);
                        toInsert.LedgerDimension            = str2Int64(range.get_Item(i,13).Value);
                        toInsert.ValidFrom                  = str2Date(range.get_Item(i,14).Text, 123);
                        toInsert.ValidTo                    = str2Date(range.get_Item(i,15).Text, 123);
                        toInsert.Worker                     = str2Int64(range.get_Item(i,16).Value);
                        toInsert.TextA                      = range.get_Item(i,17).Value;
                        toInsert.TextB                      = range.get_Item(i,18).Value;
                        toInsert.TextC                      = range.get_Item(i,19).Value;
                        toInsert.TextD                      = range.get_Item(i,20).Value;
                        toInsert.TextE                      = range.get_Item(i,21).Value;
                        toInsert.DateA                      = str2Date(range.get_Item(i,22).Text, 123);
                        toInsert.DateB                      = str2Date(range.get_Item(i,23).Text, 123);
                        toInsert.IntA                       = str2Int(range.get_Item(i,24).Value);
                        toInsert.IntB                       = str2Int(range.get_Item(i,25).Value);
                        toInsert.IntC                       = str2Int(range.get_Item(i,26).Value);
                        toInsert.doInsert();
                        rowCount  ;
                        ttsCommit;
                    }
                    
                }
            }
        }

        info("@MPL426");
    }

Thanks

I have the same question (0)
  • Suggested answer
    nunomaia Profile Picture
    25 Moderator on at

    You didn't init rowCount var before starting loop  

  • Verified answer
    Gunjan Bhattachayya Profile Picture
    35,423 on at

    Hi Riyas,

    I don't see you assigning a value to the variable worCount, Without it, the loop will only rune once. You should include this statement -

    rowCount           = (worksheet.Dimension.End.Row) – (worksheet.Dimension.Start.Row)    1;

  • Riyas ahamed F Profile Picture
    1,215 on at

    Thanks for your answer,

    but still not insert what can be issue ?

  • Suggested answer
    Gunjan Bhattachayya Profile Picture
    35,423 on at

    Hi Riyas,

    You are doing  "rowCount++;". That's not necessary. the for loop "i++" is taking care of the loop.

    Is it not inserting any record? Have you tried to debug and check the data coming from the excel file?

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
Martin Dráb Profile Picture

Martin Dráb 664 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

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

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 303 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans