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.
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.
Business Central has it own posting on the background.
If you enable that one everything goes through a Job queue and if an error is there you get a message in the list.
I also encountered this behavior last year writing a Job Queue process for nightly invoicing of shipped sales orders. If the job wrote any errors to the standards error log, it would result in the Job being set to an “error” status at the end. This resulted in the job not running the next night unless someone caught this and reset the job.
My ultimate solution to this was a subscription to the “OnAfterHandleRequest” event for the “Job Queue Dispatcher” codeunit. There set the “Job Queue Entry”. Status to “Finished”, save the record, and call the “FinalizeRun” function. This last function is what sets the status back to “Ready”.
I also have a subscription to the “OnBeforeRun” event of the same CU. I use this to conditionally set this behavior to run on only a specific job.
Hello,
You can try to modify your loop and create a job queue or a task for each of the orders (you may use the standard for that). This way most of the orders should post.
Or If you find that there is a specific error that causes this, you may want to test for that error before posting.