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

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

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

I get an error when trying to run job queue to post released sales orders

(0) ShareShare
ReportReport
Posted on by 39
codeunit 70100 "Sales Order Auto Post"
{
    trigger OnRun()

    begin
        SalesHeader.SetRange("Document Type", SalesHeader."Document Type"::Order);
        SalesHeader.SetRange(Status, SalesHeader.Status::Released);
        // SalesHeader.setFilter("Salesperson Code", '6197|5931');
        if SalesHeader.FindFirst() then
            repeat
                SalesHeader.Xee_IsPostedFromJob := true;
                SalesHeader.Modify();
                PostSalesOrder(SalesHeader);
            until SalesHeader.Next() = 0;
    end;

    local procedure PostSalesOrder(VAR SalesHeader: Record "Sales Header")
    var
        myInt: Integer;
    begin
        if salesPost.Run(SalesHeader) then;

    end;

    var
        SalesHeader: Record "Sales Header";
        salesPost: Codeunit "Sales-Post (Yes/No)";
        sal: Codeunit "Sales-Post";
        SalesOrder: page "Sales Order";
}
This is my code and i get this error 
Job finished executing. Status: Error Error: An error occurred and the transaction is stopped. Contact your administrator or partner for further assistance.
I have the same question (0)
  • Suggested answer
    TabrezAjaz Profile Picture
    202 on at

    Hi Muaaz Deyab

    It seems like there could be a few issues with your code that are causing the error. Here are a few things to check:

    1. Make sure that the variables and functions you are using are declared and defined properly. For example, you are using the variable myInt but it is not being used or defined anywhere in the code.

    2. Check if the SalesPost.Run function is returning an error message. You can try adding a condition to handle any errors that may occur during the posting process. For example:

    if not SalesPost.Run(SalesHeader) then begin
         Error('Error posting sales order %1', SalesHeader."No.")
    ;
         // log your error in some table and later resolve the identified cause 
         // use some already available functions like GetLastErrorText()., GetLastErrorCode() for reference.
    end;
    1. Ensure that the permissions for the user running the job are set up correctly. The user should have the necessary permissions to post sales orders and modify sales header records.

    2. Check if there are any customizations or extensions that could be interfering with the code. Try disabling any customizations and extensions and then run the code again to see if it works.

    3. Make sure that the job is being run with the appropriate company context. If the job is being run in a different company context than the sales orders that need to be posted, then it may not work.

    I hope these tips help you resolve the issue. If you need further assistance, feel free to ask!

  • Muaaz Deyab Profile Picture
    39 on at

    I tried the same thing on purchase order and it runs successfully and the posting works when doing manually so I don`t think it is permission problem, and I tried writing this

    if not SalesPost.Run(SalesHeader) then begin

        Error('Error posting sales order %1', SalesHeader."No.");

        // log your error in some table and later resolve the identified cause

        // use some already available functions like GetLastErrorText()., GetLastErrorCode() for reference.

    end;

    but it does not go into the SalesPost.Run() it just crash there

  • Suggested answer
    Nitin Verma Profile Picture
    21,812 Moderator on at

    Did you debug the problem?

  • Suggested answer
    Nitin Verma Profile Picture
    21,812 Moderator on at

    Also did you try with Ship and Invoice Boolean fields value, what you want to post?

  • Muaaz Deyab Profile Picture
    39 on at

    Yes I tried debuging but it does not give any good info

    and I added these to prevent the GUI

       [EventSubscriber(ObjectType::Codeunit, 81, 'OnBeforeConfirmSalesPost', '', FALSE, FALSE)]

       local procedure SkipDialogs(var DefaultOption: Integer; var HideDialog: Boolean; var SalesHeader: Record "Sales Header")

       begin

           if SalesHeader."Document Type" = SalesHeader."Document Type"::Order then begin

               if SalesHeader.Xee_IsPostedFromJob then begin

                   DefaultOption := 3;

                   HideDialog := true;

                   SalesHeader.Ship := true;

                   SalesHeader.Invoice := true;

               end;

           end;

       end;

       [EventSubscriber(ObjectType::Codeunit, 80, 'OnBeforePostSalesDoc', '', false, false)]

       local procedure HideProgressDialog(var HideProgressWindow: Boolean; var SalesHeader: Record "Sales Header")

       begin

           if SalesHeader."Document Type" = SalesHeader."Document Type"::Order then

               if SalesHeader.Xee_IsPostedFromJob then begin

                   HideProgressWindow := true;

               end;

       end;

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the April Top 10 Community Leaders

These are the community rock stars!

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

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 2,003 Super User 2026 Season 1

#2
YUN ZHU Profile Picture

YUN ZHU 1,225 Super User 2026 Season 1

#3
AndrewThomas81 Profile Picture

AndrewThomas81 1,192

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans