Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

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

Batch ignores While loop

(0) ShareShare
ReportReport
Posted on by 1,628

To start, without too much detail, I have created a custom class that extends RunBaseBatch.  I have done this before, but never experienced this issue before.

When I run the code it does exactly what I want, looping through the records and updating the data as desired.

When I run the code in Batch (Check the box for batch processing), the While Loop is ignored.  1 record is processed and the program stops.

I have refreshed the environment, done a full CIL compilation, Database Sync, Deleted the XPPIL files, Deleted my AUC files, Cleared Caches...

Again, the code runs flawlessly over and over when NOT in Batch, but check Batch Process and only 1 record is processed and it ends.

I'm sure it is something simple I am overlooking.  Any help is greatly appreciated.  Thanks!

  • André Arnaud de Calavon Profile Picture
    293,207 Super User 2025 Season 1 on at
    RE: Batch ignores While loop

    Hi Ansel,

    As a start, it would be good to review the methods runsImpersonated, pack, unpack and the method containing your loop.

  • FAC.Ansel Profile Picture
    1,628 on at
    RE: Batch ignores While loop

    Sergei,

    I have done a number of iterations of my code.  With the first iteration and when I found the issue, when sending to Batch, then looking at the Batch Job, the status ends with "Error" and in the Log I see the error message which indicated that the code successfully finished the Pick for 1 or the 2 entries, then went on to the Put where it failed, which it should do because it did not finish picking the whole Work before continuing on to the Put.  So, I put in some Infolog text to try to follow the code when it goes to batch.

    When I run the program NOT in Batch and it completes successfully, I see the following:

    NoBatch.jpg

    Then, when I run in Batch, I get the following:

    0535.Batch.jpg

    I then removed the "Put" code and when I do, the batch job completes successfully (Batch status is Ended), BUT only 1 line of the 2 line Work has been processed.

    I have a While loop that should loop through all the Picks, then a While loop that should loop through all the Puts, which it does perfectly when not in Batch, but when sent to Batch, 1 record is processed successfully completely disregarding my other data.  Another example would be, if I only have 1 line to pick and put, then the Batch job will run successfully, but if I have more than 1 pick line, then in Batch it fails to continue on beyond the 1 single record.

  • Sergei Minozhenko Profile Picture
    23,091 on at
    RE: Batch ignores While loop

    Hi Ansel,

    Are you sure that the batch job didn't fail after the 1st iteration? Have you checked the batch job log? It would be nice to see how the method run is designed and what variables are used in pack\unpack methods.

  • FAC.Ansel Profile Picture
    1,628 on at
    RE: Batch ignores While loop

    Andre',

    Thank you for your assistance.

    My custom class was created to iterate through a new table with entries used to process WHS work.  It uses existing code to do most of the work, but uses the data in the table to fill in the missing pieces of data needed to process Work.  This will allow the users to submit large transactions through Batch overnight instead of watching a spinning wheel on a handheld device.

    I have created the class from scratch twice and get the same results (Works when not in Batch, doesn't work when processed in Batch).

    After not having success the first time through, I followed the steps below to try to find where I may have gone wrong:

    docs.microsoft.com/.../walkthrough-extending-runbasebatch-class-to-create-and-run-a-batch

    Instead of posting all the methods and code below, here are the methods in my class currently.  Let me know which method would be of most interest and help:

    2055.screenshot.jpg

  • André Arnaud de Calavon Profile Picture
    293,207 Super User 2025 Season 1 on at
    RE: Batch ignores While loop

    Hi Ansel,

    Can you share some details of your custom class? What methods did you use and did you ensure the batch can run IL coding?

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

Daivat Vartak – Community Spotlight

We are honored to recognize Daivat Vartak as our March 2025 Community…

Announcing Our 2025 Season 1 Super Users!

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

Kudos to the February Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 293,207 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,923 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156 Moderator

Leaderboard

Product updates

Dynamics 365 release plans