D365 Business Central : Using Service-to-Service (S2S) Authentication with Job Queue
Minor update 21.2 for Business Central 2022 release wave 2 has just been released. You can check the release update here. It’s a minor update, but one of the most important part is that the integrated session using service-to-service (S2S) authentication can now schedule tasks. This is great news for people who are dealing with integration.
Prior to the update, scheduled tasks must be created and executed in the context of a licensed user, so we cannot create or execute a task with the S2S authentication. One of the possible way is to create a new table to store the request and have another recurring job queue to process the request.
With update 21.2, we can now use S2S authentication to create job queue directly.
Let’s test this by creating a new 21.2 environment.
We can create and run a simple job queue using this code.
var
JobQueueEntry: Record "Job Queue Entry";
begin
JobQueueEntry.Init();
JobQueueEntry.Validate("Object Type to Run", JobQueueEntry."Object Type to Run"::Codeunit);
JobQueueEntry.Validate("Object ID to Run", Codeunit::"Test Job Queue_TNG");
JobQueueEntry.Insert(true);
JobQueueEntry.Validate("Earliest Start Date/Time", CurrentDateTime());
JobQueueEntry.Modify(true);
end;
If we try to call this on BC 21.1, we will get the error message.
You do not have permission to create or run scheduled tasks
If we try to call the same logic on BC 21.2, we no longer get the error. We can confirm this by checking the Job Queue Log Entries.