Skip to main content

Notifications

Microsoft Dynamics NAV (Archived)
Suggested answer

Job queue issue

(0) ShareShare
ReportReport
Posted on by Microsoft Employee

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

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Job queue issue

    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? 

  • Jens Glathe Profile Picture
    Jens Glathe 6,092 on at
    RE: Job queue issue

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

    CHANGECOMPANY changes to the company you're already in.

  • Suggested answer
    Jens Glathe Profile Picture
    Jens Glathe 6,092 on at
    RE: Job queue issue

    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

  • keoma Profile Picture
    keoma 32,675 on at
    RE: Job queue issue

    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.

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Job queue issue

    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?

  • Suggested answer
    keoma Profile Picture
    keoma 32,675 on at
    RE: Job queue issue

    increase the time between 2 runs.then try again.

    also remove line

    ImportCustomer.CHANGECOMPANY(COMPANYNAME);

    makes that a difference.

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

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Announcing Forum Attachment Improvements!

We're excited to announce that attachments for replies in forums and improved…

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,965 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 230,817 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans