Skip to main content

Notifications

Announcements

No record found.

Small and medium business | Business Central, N...
Suggested answer

Trying to get TaskScheduler to work

Posted on by 3

Dear Business Central / AL developer experts,

I am trying to get the TaskScheduler to work. I can schedule a task, it is visible in the "Scheduled Tasks" table. At the scheduled time, a row in the "Session Events" table appears. But the task does not do it's usual work. What can be the reason for this?

I wrote a test CodeUnit, if I run it by hand it writes a message to a custom log table. If I schedule it, the message does not get written.

Please see the code below.
Also added: a zip of the AL test project (with the MS apps removed to make it uploadable).

===========================

codeunit 60001 TaskSchedulerTest
{
    //This is the Task to perform.
    trigger OnRun()
    var
        Log: Record MessageLog;
    begin
        Log.Log(3, 'The test CodeUnit 60001 has run!');
    end;

    //This should schedule the Task, a chosen number of minutes after NOW.
    procedure ScheduleMe()
    var
        MinutesAfterNow: Integer;
        TargetCompany: Text;
        NotBefore: DateTime;
        TaskGuid: Guid;
    begin
        //Configure the scheduling
        MinutesAfterNow := 20;
        TargetCompany := 'Entocare CV';  //Change it

        //Schedule this CodeUnit
        NotBefore := CreateDateTime(Today(), Time())   MinutesAfterNow * 60 * 1000;
        if not TaskScheduler.CanCreateTask() then
            Error('CanCreateTask is false.');
        TaskGuid := TaskScheduler.CreateTask(70001, 0, true, TargetCompany, NotBefore);
        Message('Scheduled: '   TaskGuid);
    end;
}

TaskSchedulerTest.zip

  • Wolter Kaper Profile Picture
    Wolter Kaper 3 on at
    RE: Trying to get TaskScheduler to work

    Andy,

    Okay, thanks, I'll do that...!

    It's perhaps best if you delete my post in this forum otherwise people can accuse me of cross-posting.

    With best regards, Wolter

  • Andy Sather Profile Picture
    Andy Sather on at
    RE: Trying to get TaskScheduler to work

    Hello Wolter.  You can still post Dev questions on here on this forum.  I am just saying we do not have Microsoft Employees in Development that monitor this forum.  The support team that monitors this forum are application engineers.

    The other 2 forums are more Dev related and could get you the answers you are looking for faster.

  • Wolter Kaper Profile Picture
    Wolter Kaper 3 on at
    RE: Trying to get TaskScheduler to work

    Hello,

    The second one of your three links points to the Dynamics 365 Business Central forum. It looks exactly like the one you are telling me is not right. I'll use the other two, thanks.

    A year ago there were a lot of dev questions here, and answers too. Mm... Okay.

  • Suggested answer
    Andy Sather Profile Picture
    Andy Sather on at
    RE: Trying to get TaskScheduler to work

    Hello  - We currently do not have Dev support via the Dynamics 365 Business Central forums, but I wanted to provide you some additional resources to assist.  If you need assistance with debugging or coding I would recommend discussing this on one of our communities.

    www.yammer.com/dynamicsnavdev

    community.dynamics.com/.../758

    dynamicsuser.net/.../developers

    I will open this up to the community in case they have something to add.

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,214 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans