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 :
Microsoft Dynamics NAV (Archived)
Suggested Answer

Job queue issue

(0) ShareShare
ReportReport
Posted on by

Hi all

I have some periodic issues with the job queue in nav. In nav i have created a "ImportCustomer" table which gets data from a store procedure. To create customers in navision from this table there is a CreateCustomerFromImport CU. This Codeunit is inserted as a job queue entry and creates customers every minute. After some time there is not created anymore customers even though the job queue entry is ready and running and there are records in the ImportCustomer table. 

If I run the codeunit directly outside the job queue it works (but strangely today it did not work with a different login?)

Any help is appreciated!

CreateCustomeFromImport:

ImportCustomer.CHANGECOMPANY(COMPANYNAME);
ImportCustomer.SETRANGE(Created,FALSE);
IF(ImportCustomer.FINDFIRST) THEN BEGIN
REPEAT
Customer.INIT;
Customer.VALIDATE("No.",ImportCustomer."Customer No.");
Customer.VALIDATE(Name,ImportCustomer.Name);
Customer.VALIDATE(Address,ImportCustomer.Address);
Customer.VALIDATE("Address 2",ImportCustomer."Address 2");
Customer.VALIDATE("Post Code",ImportCustomer."Post Code");
Customer.VALIDATE(City,ImportCustomer.City);
Customer.VALIDATE("E-Mail",ImportCustomer."E-Mail");
Customer.VALIDATE("Country/Region Code",ImportCustomer."Country/Region Code");
Customer.VALIDATE("VAT Registration No.",ImportCustomer."VAT Registration No.");
Customer.VALIDATE("EAN No.",ImportCustomer."EAN No.");
Customer.VALIDATE("Phone No.",ImportCustomer."Phone No.");
Customer.VALIDATE("Language Code",ImportCustomer."Language Code");
Customer.VALIDATE("Currency Code",ImportCustomer."Currency Code");
Customer.VALIDATE("Gen. Bus. Posting Group",ImportCustomer."Gen. Bus. Posting Group");
Customer.VALIDATE("VAT Bus. Posting Group",ImportCustomer."VAT Bus. Posting Group");
Customer.VALIDATE("Customer Posting Group",ImportCustomer."Customer Posting Group");
Customer.VALIDATE("Payment Terms Code",ImportCustomer."Payment Terms Code");
Customer.VALIDATE("Reminder Terms Code",ImportCustomer."Reminder Terms Code");
Customer.VALIDATE("Responsibility Center",ImportCustomer."Responsibility Center");
Customer.INSERT(TRUE);

ImportCustomer."Customer No." := Customer."No.";
ImportCustomer.Created := TRUE;
ImportCustomer.MODIFY;
UNTIL ImportCustomer.NEXT = 0;
END;

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    keoma Profile Picture
    32,729 on at

    increase the time between 2 runs.then try again.

    also remove line

    ImportCustomer.CHANGECOMPANY(COMPANYNAME);

    makes that a difference.

  • Community Member Profile Picture
    on at

    I will try to do that and reply back when I know if it had helped. Could it be that I should add a line such as

    Customer.LOCKTABLE?

  • keoma Profile Picture
    32,729 on at

    locktable can be helpful, if it can be that an other process at the same time wants to write to the customer table. but i'm not sure, if that helps. it's  a bit strange that it also does not work, if you start the codeunit directly using a different user account. could be a permission issue.

  • Suggested answer
    Jens Glathe Profile Picture
    6,092 on at

    Hi albor,

    there is an old "bug" or "change in behaviour" that leads to the stopping of the job queue entry once it has hit an error (for whatever reason). This has been fixed in NAV2016 (now the job queue sleeps between the retries, as specified), but if the retries fail, it will stop after the retries until admin intervention. If that's not what you want, I would recommend to change the code in CU 451, HandleRequest():

        LOCAL PROCEDURE Process@9(VAR JobQueueEntry@1000 : Record 472);
        VAR
          Success@1001 : Boolean;
          AttemptToRun@1002 : Boolean;
          NoOfAttempts@1003 : Integer;
        BEGIN
          COMMIT;
          AttemptToRun := TRUE;
          WHILE NOT Success AND AttemptToRun DO BEGIN
            IF (NoOfAttempts > 0) AND (JobQueueEntry."Rerun Delay (sec.)" > 0) THEN BEGIN
              JobQueueEntry.LOCKTABLE;
              JobQueueEntry.GET(JobQueueEntry.ID);
              JobQueueEntry.SetErrorMessage(GETLASTERRORTEXT);
              JobQueueEntry.MODIFY(TRUE);
              COMMIT;
              SLEEP(JobQueueEntry."Rerun Delay (sec.)" * 1000);
            END;
    
            Success := CODEUNIT.RUN(CODEUNIT::"Job Queue Start Codeunit",JobQueueEntry);
            IF NOT Success THEN BEGIN
              NoOfAttempts := NoOfAttempts + 1;
              AttemptToRun := NoOfAttempts < JobQueueEntry."Maximum No. of Attempts to Run";
            END;
          END;
          JobQueueEntry.LOCKTABLE;
          IF JobQueueEntry.GET(JobQueueEntry.ID) THEN
            JobQueueEntry.TESTFIELD(Status,JobQueueEntry.Status::"In Process")
          ELSE
            ERROR(Text001);
          COMMIT;
          IF Success THEN
            JobQueueEntry.SetStatus(JobQueueEntry.Status::Finished)
          //PX001s px.jgl force the next execution despite errors even with retries
          ELSE begin
    if JobQueueEntry."Force ready state after errors" then begin // new field
    JobQueueEntry.SetErrorMessage(GETLASTERRORTEXT); // keep the last error text JobQueueEntry.SetStatus(JobQueueEntry.Status::Ready);
    end else begin
    JobQueueEntry.SetError(GETLASTERRORTEXT);
    end; end; //PX001e px.jgl COMMIT; END;


    This should do the trick.

    with best regards

    Jens

  • Jens Glathe Profile Picture
    6,092 on at

    CHANGECOMPANY and VALIDATE don't go together very well, or only when

    CHANGECOMPANY changes to the company you're already in.

  • Community Member Profile Picture
    on at

    Thanks for the replies so far. I really appreciate the help

    The issue is both in nav2015 and nav2016

    I have erased the CHANGECOMPANY line. For the record it changed to the company which I was already in.

    Today I have experienced the issue again several times. The job queue entry was running succesfully and still it was not importing the customer/sales orders until I ran the codeunit(s) manually.

    Could it be related to how the job queue is run? (new job but same issue)

    JobQueue1.PNG

    JobQueue1.PNG

    Another thing. Is it possible to debug the job queue entry? I mean can I have the debugger running and then debug when the job queue entry is running? 

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 March Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics NAV (Archived)

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans