Options

Try Functions

LgooLgoo Member Posts: 45
edited 2016-06-29 in NAV Three Tier
hi,

i observed a weird behavior with try-functions in NAV 2016 and want to ask wether you run in to the same error.
So if a Job Queue is running a function and in this function i got a try-function that inserts some general journal lines that run in an error at the line with the insert, the Job Queue stops with error. My expection was, that the try-funciton will return only a false so i can run the next line to insert a document.

Here's the code, the Job Queue runs the 'OnRun':
OnRun()
  WITH QueueLines DO BEGIN
    IF FINDSET THEN BEGIN
      repeat
        success := TryPostDocument(GUID);
        WriteLog(GUID,success);
      until next = 0; 
    END;
  END;


TryPostDocument(pGUID : GUID)
Importline.GET(pGUID); //<--- If not get the function return correctly "FALSE" and writes some logs in 'WriteLog'
.
.
.

  WITH GenJournalLine DO BEGIN
    INIT;
    "Line No." := 1;
    VALIDATE("Account Type",GenJournalLine."Account Type"::Customer);
    VALIDATE("Account No.",Importline.Customer);
    VALIDATE("Document Type",GenJournalLine."Document Type"::"Credit Memo");
    VALIDATE("Posting Date", Importline."Posting Date");
    "Journal Template Name" := Template;
    "Journal Batch Name" := Name;
    VALIDATE("Document No.",DocumentNo);
    Description := Importline.Description;
    VALIDATE("Credit Amount", Importline.Amount);
    INSERT;

    INIT;
    "Line No." := 1;
    VALIDATE("Account Type",GenJournalLine."Account Type"::"G/L Account");
    VALIDATE("Account No.",10000);
    VALIDATE("Document Type",GenJournalLine."Document Type"::"Credit Memo");
    VALIDATE("Posting Date", Importline."Posting Date");
    "Journal Template Name" := Template;
    "Journal Batch Name" := Name;
    VALIDATE("Document No.",DocumentNo);
    Description := Importline.Description;
    VALIDATE("Debit Amount", Importline.Amount);
    INSERT;  //<---- Error cause the same Line No, The function do not return anything, but the Job Queue stops...
  END;


In the Job Queue log i get the error '..cannot insert because lineNo allready excists...'
So i tried it with:
IF NOT INSERT THEN
  ERROR(GETLASTERRORTEXT);

I receive only the error code from the GETLASTERRORTEXT funciton.
As you can see, it is possible to make a work-around and write an own error text when an insert fails. But i dont like it, cause i dont know where else this try function not realy work and i think its a bug.

Best Answer

Answers

  • Options
    LgooLgoo Member Posts: 45
    edited 2016-06-29
    The try-function never return 'FALSE', so i cant change the status of the queue..
    What do you mean with a safeguard for try functions?

    Edit:
    Hmm ok sems to be crazy shit this 'try-functions' in NAV. Realy what did MS excpected when they implemented it? Its only usable if the transaction was rolle backed...

    Thanks Peter+is1 !
Sign In or Register to comment.