✏️ Explanatory Question

BatchHeader.addTask() vs BatchHeader.addRuntimeTask()

👁 39 Views
📘 Detailed Answer
🟢 Easy
39
Total Views
10
Related Qs
0%
Progress
No previous question
No next question
💡

Answer with Explanation

In D365 Finance and Operations (FO), addTask and addRuntimeTask are both methods used to add tasks to a batch job, but they have key differences. addTask adds a batch-enabled class to the batch header, which will be scheduled for execution. addRuntimeTask, on the other hand, adds a dynamic batch task that only exists for the current run and is deleted afterward.

Here's a more detailed breakdown:

addTask:

 batchHeader.addTask(controller);
  • Adds a persistent batch task: The task is added to the batch header and persists in the batch job's configuration, even after the job has been executed.
  • Used for scheduled batch jobs: Typically used for tasks that are part of a scheduled batch job and need to be executed regularly or on a specific schedule.
  • Can be part of a batch group: The task can be assigned to a specific batch group, which determines which AOS servers will process it. 
addRuntimeTask:

 batchHeader.addRuntimeTask(contrl, batchHeader.parmBatchHeaderId());
  • Adds a transient, dynamic task: The task is created and executed during the current batch job run, but it doesn't persist in the batch header after the run completes.
  • Used for one-time or temporary tasks: Suitable for tasks that need to be executed during a specific run but don't need to be persisted or scheduled.
  • Doesn't have a predefined batch group: Runtime tasks are not associated with a specific batch group, but they can inherit settings from another task using the inheritFromTaskId parameter. 

When to use which:

  • Use addTask when you need to define a persistent batch task that will be part of a scheduled job, potentially with specific dependencies or batch group assignments. 
  • Use addRuntimeTask when you need to add a dynamic task that only exists for the current run, often used for one-time processes or tasks that need to be executed on demand. 

In essence, addTask is for building the batch job's structure, while addRuntimeTask is for adding tasks that will only be executed during the current run. 

No previous question
No next question