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, ...
Suggested Answer

Batch job classes to skip processing on criteria

(2) ShareShare
ReportReport
Posted on by 6,478
Hello,
Which class / method would be the best to use as COC and to place the custom code in both runBase and sysoperational framework?
Our goal is to skip batch jobs from executing on some week days if the week day is a public holiday.
We already have a custom table for holidays.
I'm searching for some general place, where I can apply my logic.
I can easily do it for the specific batch jobs, but I want the logic to be applied for all the batch jobs, which will have a setup to custom holiday table.
Thanks
Categories:
I have the same question (0)
  • Martin Dráb Profile Picture
    237,662 Most Valuable Professional on at
    Batch job classes to skip processing on criteria
    Please tell us more about the expected behaviour.
     
    Do you want the batch to run and end immediately if the condition is met? Or do you want to actually prevent scheduling on those days (either manually or by recurrence)?
     
    Are you 100% sure that you want it for all batches, including system batches, integration, email distributor etc.? It doesn't sound like a good idea to me (and it's actually not possible with some system batches). On the contrary, public holidays may be a good time to run some batches that would otherwise slow down the system for users.
  • Johnny Profile Picture
    6,478 on at
    Batch job classes to skip processing on criteria
    Hi Martin,
    so.. we have added relation from BatchJob table to Holidays table. We also have HolidayLines under holiday table.
    When the batch job is set to run in reccurance, we want to check if the Holidays is selected on the batch. If selected, we would like the batch job to end immediatelly.
    The holidays setup will be set only to custom batch jobs, but it is still quit a lot to write code in each batch class separatelly.
     
    Initially we have developed it just for one batch job and below is the code snippet from the method of that batch job class.
    Basically this is what I want to do, but in all "custom batch job" cases.
    BatchHeader batchHeader = BatchHeader::getCurrentBatchHeader();
    if (batchHeader)
    {
        HolidayLine holidayLine = BatchJobHolidaySetupHelper::holidayToday(batchHeader.parmBatchHeaderId());
        if (holidayLine)
        {
            throw warning(strFmt("@XXX", holidayLine.HolidayDate, holidayLine.Name));
        }
    }
     
  • Suggested answer
    Martin Dráb Profile Picture
    237,662 Most Valuable Professional on at
    Batch job classes to skip processing on criteria
    Then consider doing it in BatchRun::runJobStatic().
  • Johnny Profile Picture
    6,478 on at
    Batch job classes to skip processing on criteria
    Hi Martin,
    I tried to debug in BatchRun::runJobStatic().
    It looks like this method isn't executed when Batch job is executed.
    Or at least in my case.
    Normally breakpoints are hit when I have Batch and iisexpress attached.
     I have also just added info("Test") to a COC method of runJobStatic and it has not been executed.
  • Martin Dráb Profile Picture
    237,662 Most Valuable Professional on at
    Batch job classes to skip processing on criteria
    I was just looking into code before. Now I checked the actual stack trace in the debugger and I see BatchRun::runJobStaticCodeFromBuffer() there:
     
     
    The problem is that neither runJobStaticCodeFromBuffer() nor runJobStaticFromBuffer() can be extended (one is private and the other one internal).
  • Suggested answer
    André Arnaud de Calavon Profile Picture
    300,716 Super User 2025 Season 2 on at
    Batch job classes to skip processing on criteria
    Hi Johnny,

    When reading this thread, there might be a huge challenge to implement this requirement with the current approach. Some methods can't be extended. 
     
    Logic where the next start date/time is calculated is also not possible to extend as it is not aware of the specific batch job in the next recurrence date time calculation (class SysRecurrence).
     
    What you can consider is developing a new batch job that runs end of the day and will check if the next date is a holiday. Then loop the specific batch jobs marked with your new Holiday setting and add one or more days to the next start date fields (multiple fields used), depending on the duration of the holiday.

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

#2
André Arnaud de Calavon Profile Picture

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

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 400 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans