✏️ Explanatory Question
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.
addTask:
batchHeader.addTask(controller);
addRuntimeTask:
batchHeader.addRuntimeTask(contrl, batchHeader.parmBatchHeaderId());
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. 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.