Dynamics 365 Business Central: scheduling job queue tasks via API

The Dynamics 365 Business Central 2022 Wave 2 version 21.2 update silently introduces a long requested feature: the possibility to schedule job queue tasks via APIs in an integrated session using Service-to-Service (S2S) authentication.

Service-to-Service (S2S) authentication is suited for scenarios where integrations are required to run without any user interaction and prior to this new version with a S2S session you was not able to schedule job queue tasks (if you tryed to do that, you received a permission error on the API call).

With Dynamics 365 Business Central version 21.2 now this is finally possible!

To show this, just create a codeunit and create the following procedure:

This procedure schedules a codeunit (here I’ve used a standard codeunit just for simplicity) as a recurring job queue task.

Now publish this codeunit as an OData endpoint (here called SDApiMgt) and call it via APIs by using S2S authentication:

Result?

No error now, but a HTTP 204 No Content success status response code indicates that a request has succeeded:

If you go on Dynamics 365 Business Central and you check the Job Queue Entries page, you can see that a Job Queue Entry record is created:

The User ID field shows that it’s my Azure Active Directory app registration that creates the task.

Please remember that to set up service-to-service authentication, you’ll have to do two things:

  • Register an application in your Azure Active Directory tenant for authenticating API calls against Business Central.
  • Grant access for that application in Business Central.

For more informations, here you have all what you need.

5 Comments

  1. Ciao Stefano,
    Good news, but…
    From the last update Job Queue doesn’t work.
    For ES localization it’s critical for send informatio to tax authorities.

    Do you know some issue reported about?
    Some service need to start?

    Like

    1. Well… was like some service that engine jobs queues was stoped. Any job queue run. Then, after update envoriment to 22.2 jobs queue works.
      Here my questions: How works job queue in SaaS? Is a database service? Is a Azure service? How we have visibility about performance or issues?
      Thanks a lot for your reply.
      Salut!

      Like

      1. Job Queue is SaaS are a NAS service running on a VM cluster (the cluster that runs the BC service tier). Best way to monitor issues is to activate telemetry. From here you have all the logs about job queue processing and status of each tasks (failed, running, etc).

        Like

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.