Skip to main content

Notifications

Announcements

No record found.

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

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

Posted on by 184
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.
  • Muaaz Deyab Profile Picture
    Muaaz Deyab 184 on at
    RE: I get an error when trying to run job queue to post released sales orders

    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;

  • Suggested answer
    Nitin Verma Profile Picture
    Nitin Verma 21,091 Super User 2024 Season 1 on at
    RE: I get an error when trying to run job queue to post released sales orders

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

  • Suggested answer
    Nitin Verma Profile Picture
    Nitin Verma 21,091 Super User 2024 Season 1 on at
    RE: I get an error when trying to run job queue to post released sales orders

    Did you debug the problem?

  • Muaaz Deyab Profile Picture
    Muaaz Deyab 184 on at
    RE: I get an error when trying to run job queue to post released sales orders

    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
    TabrezAjaz Profile Picture
    TabrezAjaz 190 on at
    RE: I get an error when trying to run job queue to post released sales orders

    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!

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,214 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans