web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Small and medium business | Business Central, N...
Suggested Answer

Post Purchase Document via Job Queue (Custom)

(0) ShareShare
ReportReport
Posted on by 12

We want to create a Job Queue which will post purchase documents in a specific state. You would have previously achieved this via looping through the purchase headers and calling If Codeunit.Run...In this scenario previously you were able to retreive an error message, example below. 

if PurchaseHeader.findset() then
repeat
if not Codeunit.Run(Codeunit::"Purch-Post", PurchaseHeader) then
// Do something with GetLastErrorText
until PurchaseHeader.Next() = 0;

Importantly, the Job Queue Entry would not fail at this point either, as the error was handled separately. I found this blog post with a similar query, but does anyone know how this is achieved now. 

https://github.com/microsoft/ALAppExtensions/issues/16362

Essentially, we want to post orders via a job queue, and store any errors on the document. But we do not want the Job Queue Entry itself to go into error. 

I have the same question (0)
  • Suggested answer
    Marco Mels Profile Picture
    on at
    RE: Post Purchase Document via Job Queue (Custom)

    Hello,

    We currently do not have dedicated 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

    www.dynamicsuser.net/.../14

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

    Thanks.

  • Suggested answer
    Nitin Verma Profile Picture
    21,698 Moderator on at
    RE: Post Purchase Document via Job Queue (Custom)

    You have to write one more codeunit and write your posting functions in that codeunit, and use that codeunit in another objects like below

    if not PostingCodeunit.run then

    begin

     LogyourError here with functions GETLASTERRORTEXT.

    end;

    by doing above your job queue will never be in Error.

    Thanks.

  • TESDEveloper Profile Picture
    12 on at
    RE: Post Purchase Document via Job Queue (Custom)

    Thank you Nitin,

    I have the following setup:

    Codeunit A is the target codeunit of the Job Queue.

    In Codeunit A I have a function which calls codeunit B with if not CodeunitB.Run then;

    Codeunit B Run is then calling if not PurchPost.Run.

    I think the error context however is at the job queue level, and therefore even with the additional codeunit, the error is still considered under the context of the job queue. My Job Queue is still failing with a posting date error.

  • Suggested answer
    Nitin Verma Profile Picture
    21,698 Moderator on at
    RE: Post Purchase Document via Job Queue (Custom)

    You have to write your PurchPost.run on OnRun trigger of Codeunit B.

    Thanks.

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Small and medium business | Business Central, NAV, RMS

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 3,377

#2
Jainam M. Kothari Profile Picture

Jainam M. Kothari 2,696 Super User 2025 Season 2

#3
YUN ZHU Profile Picture

YUN ZHU 1,512 Super User 2025 Season 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans