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

robthemobbrobthemobb Posts: 12Member
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 Posts: 9Member
    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 Posts: 123Member
    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 Posts: 12Member
    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 Posts: 180Member
    edited 2018-02-14
    Have you checked that the error is indeed triggered when executing SalesHeaderG.GET or may be by another command?
  • robthemobbrobthemobb Posts: 12Member
    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 Posts: 36Member
    Please Check SalesHeader Table Primary Key , Is It Default Or You Change It?
  • robthemobbrobthemobb Posts: 12Member
    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 Posts: 36Member
    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 Posts: 1,488Member
    edited 2018-02-15
    <DELETED>
    Sorry, somehow missed that you already have SalesHeaderG.RESET line in your code
    Slawek Guzek
    Poszukuje programistow znajacych Microsoft Dynamics NAV
  • NavSolutionNavSolution Posts: 36Member
    Try SETRANGE , SETFILTER
  • AKAK Posts: 180Member
    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 Posts: 83Member
    I look forward to the solution as a child on the ice cream :)
    Regards
    xStepa
  • Slawek_GuzekSlawek_Guzek Posts: 1,488Member
    Can you post here the complete text definiion of your page?
    Slawek Guzek
    Poszukuje programistow znajacych Microsoft Dynamics NAV
  • BlackTigerBlackTiger Posts: 1,109Member
    Where did you put your code?
    "You can’t just ask customers what they want and then try to give that to them.
    By the time you get it built, they’ll want something new.” Steve Jobs
  • YutavoYutavo Posts: 7Member
    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.