web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics NAV (Archived)

Setrange problem

(0) ShareShare
ReportReport
Posted on by 2,582

Hi all,

I have written a code on Post action of Purchase order page. Code snippet of it is given below.

PurchaseLine.RESET;
PurchaseLine.SETRANGE("Document No.","No.");
IF PurchaseLine.FINDFIRST THEN
MESSAGE('Purchase header no %1',"No.");
MESSAGE('Purchase line document no %1',PurchaseLine."Document No.");
REPEAT
PostedGateEntryHeaderTable.RESET;
PostedGateEntryHeaderTable.SETRANGE("No.",PurchaseLine."Gate Entry No.")
IF PostedGateEntryHeaderTable.FINDFIRST THEN BEGIN

This code I have written on the post action of purchase order page.

But the problem is that while I give this statement highlighted above, the "No." field which I want I of PostedGAteEntryHeaderTable but it is taking "No." of Purchase Header table by default.

Screenshot is attached which shows No. field to be of Purchase header table.

Kindly suggest

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Mohana Yadav Profile Picture
    60,997 Super User 2025 Season 2 on at

    Screenshot is not available.

    can you please explain below sentence

    But the problem is that while I give this statement highlighted above, the "No." field which I want I of PostedGAteEntryHeaderTable but it is taking "No." of Purchase Header table by default.

  • Tina Menezes Profile Picture
    2,582 on at

    Error-in-setrange.PNG

    No. field should be of posted gate entry table but it is of Purchase header table 38

  • Verified answer
    Mohana Yadav Profile Picture
    60,997 Super User 2025 Season 2 on at

    It must be an issue of intellisense but while execution it will consider from posted gate entry table only.

    or you can also write

    PostedGateEntryHeaderTable.SETRANGE(PostedGateEntryHeaderTable."No.",PurchaseLine."Gate Entry No.")

  • Suggested answer
    Yogesh Kulkarni_ Profile Picture
    1,762 on at

    Hi,

    In command, PostedGateEntryHeaderTable.SETRANGE("No.",PurchaseLine."Gate Entry No.")

    No. will be of Posted Gate Entry Header only.

    In field paramater of SETRANGE function, field is of calling Record variable.

    You can refer below link:

    https://msdn.microsoft.com/en-us/library/dd355053.aspx

    -Yogesh Kulkarni
    Please verify, if you find answer helpful.

  • Luc van Vugt Profile Picture
    on at

    Tine, what do you exactly mean with:

    [quote user="Tina Menezes"]

    But the problem is that while I give this statement highlighted above, the "No." field which I want I of PostedGAteEntryHeaderTable but it is taking "No." of Purchase Header table by default.

    [/quote]

    What makes you draw this conclusion?

  • Verified answer
    Amol Salvi Profile Picture
    18,698 on at

    You need to write this way

    PurchaseLine.RESET;
    PurchaseLine.SETRANGE("Document No.","No.");
    IF PurchaseLine.FINDFIRST THEN
    MESSAGE('Purchase header no %1',"No.");
    MESSAGE('Purchase line document no %1',PurchaseLine."Document No.");
    REPEAT
    PostedGateEntryHeaderTable.RESET;
    PostedGateEntryHeaderTable.SETRANGE(PostedGateEntryHeaderTable."No.",PurchaseLine."Gate Entry No.")
    IF PostedGateEntryHeaderTable.FINDFIRST THEN BEGIN

  • Tina Menezes Profile Picture
    2,582 on at

    Hi Luc van Vugt,

    In my C/AL code it was taking Purchase Header record 38 variable and even in the debugger the correct value wasn't getting fetched. I have attached a screenshot which shows the same.

  • Tina Menezes Profile Picture
    2,582 on at

    Thanks all.

    My issue is solved.

  • Luc van Vugt Profile Picture
    on at

    Hi Tina, so that other may profit form your findings could you please share the solution?

  • Tina Menezes Profile Picture
    2,582 on at

    Hi, Sure!

    This was my initial code.

    PurchaseLine.RESET;

    PurchaseLine.SETRANGE("Document No.","No.");

    IF PurchaseLine.FINDFIRST THEN

    MESSAGE('Purchase header no %1',"No.");

    MESSAGE('Purchase line document no %1',PurchaseLine."Document No.");

    REPEAT

    PostedGateEntryHeaderTable.RESET;

    PostedGateEntryHeaderTable.SETRANGE("No.",PurchaseLine."Gate Entry No.")

    IF PostedGateEntryHeaderTable.FINDFIRST THEN BEGIN

    As suggested from the solutions given above, I replaced the above line which is shown in red colour with the below statement:

    PostedGateEntryHeaderTable.SETRANGE(PostedGateEntryHeaderTable."No.",PurchaseLine."Gate Entry No.");

    This solved my issue.

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics NAV (Archived)

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans