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, ...
Unanswered

Batch ignores While loop

(0) ShareShare
ReportReport
Posted on by 1,632

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!

I have the same question (0)
  • André Arnaud de Calavon Profile Picture
    301,130 Super User 2025 Season 2 on at

    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?

  • FAC.Ansel Profile Picture
    1,632 on at

    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

  • Sergei Minozhenko Profile Picture
    23,093 on at

    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,632 on at

    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.

  • André Arnaud de Calavon Profile Picture
    301,130 Super User 2025 Season 2 on at

    Hi Ansel,

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

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 451 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

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

#3
BillurSamdancioglu Profile Picture

BillurSamdancioglu 239 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans