Options

GET Error

cavalcanti_spacecavalcanti_space Member Posts: 49
Hi guys,

I have this code on a report. the TempInvSalesHeader record is set as temp.

Item Ledger Entry - OnAfterGetRecord()

IF NOT TempInvSalesHeader.GET("Invoice No.") THEN BEGIN
InvSalesHeader.GET("Invoice No.");
TempInvSalesHeader := InvSalesHeader;
TempInvSalesHeader.INSERT;
END;

When I run it I get this error:

Sales Invoice Header No. 'NFVR00002' does not exist.

Does anyone know How I can sort this out???????

Cheers

Answers

  • Options
    mohana_cse06mohana_cse06 Member Posts: 5,504
    IF NOT TempInvSalesHeader.GET("Invoice No.") THEN BEGIN
    InvSalesHeader.GET("Invoice No.");

    Always use get with IF like in 1st line.
  • Options
    BeliasBelias Member Posts: 2,998
    IF NOT TempInvSalesHeader.GET("Invoice No.") THEN BEGIN
    InvSalesHeader.GET("Invoice No.");

    Always use get with IF like in 1st line.
    [-X
    this is not really a good rule...if you always use an "if...get" you will never receive an error...
    I often take advantage of these standard errors because:
    - no translations needed in a multilanguage environment
    - ensure data consistency
    - easy-to-debug error

    In your specific case, I think the program should act like this: you first try to get the invoice from a temptable; if there's no invoice with that no., you get the invoice from the real table and fill the temptable...if there are no invoices in the real table with that number, you MUST receive an error!
    (is 'NFVR00002' a credit memo?)

    P.S.: do you know what GET function does?it's not possible you've never seen errors like yours
    -Mirko-
    "Never memorize what you can easily find in a book".....Or Mibuso
    My Blog
  • Options
    mohana_cse06mohana_cse06 Member Posts: 5,504
    Does anyone know How I can sort this out???????

    for this, i have given that solution.

    if u have anyother solution for this please let us know.

    thanks in advance
  • Options
    David_CoxDavid_Cox Member Posts: 509
    This is simple there is no TempInvSalesHeader and no InvSalesHeader, in short there is no posted Sales Invoice with the number 'NFVR00002' on the system, once an invoice is printed the posted Sales Invoice can be deleted, go to Posted Sales Invoices and search for NFVR00002

    Is NFVR00002 part of the posted number range or was this a Journal Entry?

    So as already said you need a double condition to avoid this error
    IF (NOT TempInvSalesHeader.GET("Invoice No.")) AND
        (InvSalesHeader.GET("Invoice No.")) THEN BEGIN
          TempInvSalesHeader := InvSalesHeader;
          TempInvSalesHeader.INSERT;
    END;
    

    There ya go!

    David :D
    Analyst Developer with over 17 years Navision, Contract Status - Busy
    Mobile: +44(0)7854 842801
    Email: david.cox@adeptris.com
    Twitter: https://twitter.com/Adeptris
    Website: http://www.adeptris.com
  • Options
    BeliasBelias Member Posts: 2,998
    I think the real problem is: "how did you put 'NFVR00002' in your personalized (or english local) field invoice no."?
    If the invoice does not exists, we have 2 possibilities:
    - the program failed to assign a correct "invoice no."
    - someone deleted the sales invoice header

    For the second case, you can use david cox's solution, otherwise, you have to investigate how do you fill the "invoice no."
    -Mirko-
    "Never memorize what you can easily find in a book".....Or Mibuso
    My Blog
  • Options
    David_CoxDavid_Cox Member Posts: 509
    Belias wrote:
    I think the real problem is: "how did you put 'NFVR00002' in your personalized (or english local) field invoice no."?
    If the invoice does not exists, we have 2 possibilities:
    - the program failed to assign a correct "invoice no."
    - someone deleted the sales invoice header

    For the second case, you can use david cox's solution, otherwise, you have to investigate how do you fill the "invoice no."
    I do 100% agree, the custom "Invoice No." field may not have been assigned correctly, if we look at the original code, the "Invoice No." value is coming from the Item ledger table, how does it get populated, and what about part invoices how does it deal with them, also Item Journals of type Sale, Credit Memo entries etc:, and we do not know which version of Navision.

    But we have answered the 'GET Error' question :D

    Is this the best method, well not really, because if there are Value Entries then it would be easy to return the Invoice Number or possibly Numbers (Part Invoiced) for an Item Ledger from them rather than using this field, something like this.
    ValueEntry.RESET;
    ValueEntry.SETCURRENTKEY("Item Ledger Entry No.");
    ValueEntry.SETRANGE("Item Ledger Entry No.","Entry No.");
    ValueEntry.SETFILTER("Invoiced Quantity",'<>0');
    IF ValueEntry.FINDFIRST THEN
        REPEAT
           IF (NOT TempInvSalesHeader.GET(ValueEntry."Document No.")) AND
               (InvSalesHeader.GET(ValueEntry."Document No.")) THEN BEGIN
                TempInvSalesHeader := InvSalesHeader;
                TempInvSalesHeader.INSERT;
           END;
        UNTIL ValueEntry.NEXT=0;
    

    We do not know what this report is for, or why there is a need to return the Sales Invoice Header, I cannot see how this might be used but if the question gave a scenario of what the report would be used for, we might be able to suggest a better way or a standard report that could be modified.

    David
    Analyst Developer with over 17 years Navision, Contract Status - Busy
    Mobile: +44(0)7854 842801
    Email: david.cox@adeptris.com
    Twitter: https://twitter.com/Adeptris
    Website: http://www.adeptris.com
  • Options
    BeliasBelias Member Posts: 2,998
    IF NOT TempInvSalesHeader.GET("Invoice No.") THEN BEGIN
    InvSalesHeader.GET("Invoice No.");

    Always use get with IF like in 1st line.

    Yes, you're right David...I was questioning also the "Always" word of this post...I think that was good to clarify the "GET" error behaviour...and what's in my opinion the best use of it..
    -Mirko-
    "Never memorize what you can easily find in a book".....Or Mibuso
    My Blog
  • Options
    mohana_cse06mohana_cse06 Member Posts: 5,504
    Belias wrote:
    IF NOT TempInvSalesHeader.GET("Invoice No.") THEN BEGIN
    InvSalesHeader.GET("Invoice No.");

    Always use get with IF like in 1st line.

    Yes, you're right David...I was questioning also the "Always" word of this post...I think that was good to clarify the "GET" error behaviour...and what's in my opinion the best use of it..

    me also answered for 'GET Error' question
  • Options
    cavalcanti_spacecavalcanti_space Member Posts: 49
    I have used David´s suggestion and it is working
    Cheers
Sign In or Register to comment.