Skip to main content

Notifications

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

Event subscriber not working

Posted on by 255

Hi, I am subscribing an event of codeunit 449 -  Job Queue Start Codeunit. But I am not getting my required result. for example inset a record in custom table.

Here is my code

EventSubscriberInstance = StaticAutomatic;

    [EventSubscriber(ObjectType::Codeunit449'OnAfterRun''', true, true)]
    procedure abd(JobQueueEntry: Record "Job Queue Entry")
    begin
        Message(StrSubstNo('%1', JobQueueEntry.Status));
    end;
  • Suggested answer
    TeddyH Profile Picture
    TeddyH 12,868 Super User 2024 Season 1 on at
    RE: Event subscriber not working

    The job queue runs in the background, so you will not get any message pop-up.

    If you want to capture the error log, you need to subscribe to the right event.

    Check codeunit 450 "Job Queue Error Handler".

  • Danyal Profile Picture
    Danyal 255 on at
    RE: Event subscriber not working

    I have tried onAfterInsert and OnAfterValidate, onAfterModify but seems these triggers are not getting any hit.

    Just tried onBeforMarkAsError, but nothing happened

  • Suggested answer
    Bilal Haider Profile Picture
    Bilal Haider 45 on at
    RE: Event subscriber not working

    The event that you have mentioned in example code will run after a JobQueue is started. I do not know your exact requirements but I think you need to subscribe an event when an entry is created in Job Queue Log Entry table. If that is the case then use event like OnAfterInsert or there are many other events available for Job Queue Log Entry table. One potential event that you can use is OnBeforeMarkAsError.

    Hopefully this will help you.

    Regards,

    Bilal Haider

  • Danyal Profile Picture
    Danyal 255 on at
    RE: Event subscriber not working

    Inserting record in a custom table was just an example, this can be anything, for example generating emails etc.

    So I want to generate an email or create custom logs whenever a job goes to error. Can I use the event which I mentioned? or is there any other way?

  • Bilal Haider Profile Picture
    Bilal Haider 45 on at
    RE: Event subscriber not working

    Hi Danyal,

    What do you mean by insert a record in custom table? and what is its relation to Job Queue Start codeunit's event OnAfterRun.

    Please add more detail to it.

    Regards,

    Bilal Haider

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,253 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,188 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans