Skip to main content

Notifications

Announcements

No record found.

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

Post Purchase Document via Job Queue (Custom)

(0) ShareShare
ReportReport
Posted on by 162

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. 

  • Suggested answer
    Nitin Verma Profile Picture
    Nitin Verma 21,091 Super User 2024 Season 1 on at
    RE: Post Purchase Document via Job Queue (Custom)

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

    Thanks.

  • TESDEveloper Profile Picture
    TESDEveloper 162 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
    Nitin Verma 21,091 Super User 2024 Season 1 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.

  • Suggested answer
    Marco Mels Profile Picture
    Marco Mels 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.

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 Verified Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,445 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans