SalesHeader not found even though it is existing and filters are set correctly

robthemobbrobthemobb Member Posts: 14
Hi folks,

I have a piece of code as follows:
CLEAR(SalesHeaderG);
SalesHeaderG.RESET;
IF IsReturnOrder = '1' THEN
  SalesHeaderG.GET(SalesHeaderG."Document Type"::"Return Order", SalesOrderNumber)
ELSE
  SalesHeaderG.GET(SalesHeaderG."Document Type"::Order, SalesOrderNumber);

SalesHeaderG is a table 36 record, defined as global. The other both variables are text. If I run this code, I got following error, which is odd, because the sales header is existing obviously.

8e8qd0wcm5g9.png

However, if I change the variable SalesHeaderG to local, it works. Please, can anybody tell me why?

Answers

  • rishi_rishabh123rishi_rishabh123 Member Posts: 9
    can you double check value of SalesOrderNumber variable By putting a filter on sales header table, I can see a small ‘.’ at the end of salesHeader.”No.”.
  • SilverXSilverX Member Posts: 134
    Is the global one temporary?
    Cheers
    Carsten


    ==> How To Ask Questions The Smart Way

    This post is my own opinion and does not necessarily reflect the opinion or view of my employer.
  • robthemobbrobthemobb Member Posts: 14
    can you double check value of SalesOrderNumber variable By putting a filter on sales header table, I can see a small ‘.’ at the end of salesHeader.”No.”.

    That's the small dot which delimits the number and the customer name.
    SilverX wrote: »
    Is the global one temporary?

    No, the variable wasn't temporary. I did check. I also did some tests hard-code the sales order number into the variable. This works also. So the code didn't get access to the field from the port, when the var was global, but when it was local.
    I had some code, which is executed before the snippet I posted. But never called SalesHeaderG before.
  • AKAK Member Posts: 226
    edited 2018-02-14
    Have you checked that the error is indeed triggered when executing SalesHeaderG.GET or may be by another command?
  • robthemobbrobthemobb Member Posts: 14
    AK wrote: »
    Have you checked that the error is indeed triggered when executing SalesHeaderG.GET or may be by another command?

    Went through by debugger. It is most certainly within the call of SalesHeaderG.GET.
  • NavSolutionNavSolution Member Posts: 36
    Please Check SalesHeader Table Primary Key , Is It Default Or You Change It?
  • robthemobbrobthemobb Member Posts: 14
    Please Check SalesHeader Table Primary Key , Is It Default Or You Change It?

    It's default. I can't see any reason why someone should change it (on purpose).
  • NavSolutionNavSolution Member Posts: 36
    robthemobb wrote: »
    Please Check SalesHeader Table Primary Key , Is It Default Or You Change It?

    It's default. I can't see any reason why someone should change it (on purpose).

    Then There is No Issue In Code Check Company and Debug it.
  • Slawek_GuzekSlawek_Guzek Member Posts: 1,690
    edited 2018-02-15
    <DELETED>
    Sorry, somehow missed that you already have SalesHeaderG.RESET line in your code
    Slawek Guzek
    Dynamics NAV, MS SQL Server, Wherescape RED;
    PRINCE2 Practitioner - License GR657010572SG
    GDPR Certified Data Protection Officer - PECB License DPCDPO1025070-2018-03
  • NavSolutionNavSolution Member Posts: 36
    Try SETRANGE , SETFILTER
  • AKAK Member Posts: 226
    Have you checked that there is not another SalesHeaderG variable declared? I'm not sure how this could create your error since you use RESET, but...
  • xStepaxStepa Member Posts: 106
    I look forward to the solution as a child on the ice cream :)
    Regards
    xStepa
  • Slawek_GuzekSlawek_Guzek Member Posts: 1,690
    Can you post here the complete text definiion of your page?
    Slawek Guzek
    Dynamics NAV, MS SQL Server, Wherescape RED;
    PRINCE2 Practitioner - License GR657010572SG
    GDPR Certified Data Protection Officer - PECB License DPCDPO1025070-2018-03
  • YutavoYutavo Member Posts: 7
    Are you sure that on the moment of your code, required sales header already exist in the database?
    If you wrote your code "OnInsert" trigger - it can be the answer.
Sign In or Register to comment.