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

Announcements

No record found.

News and Announcements icon
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
    61,204 Super User 2026 Season 1 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
    61,204 Super User 2026 Season 1 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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the March Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics NAV (Archived)

#1
TAHER_El_Mehdi Profile Picture

TAHER_El_Mehdi 2

#1
sliderxb Profile Picture

sliderxb 2

#1
broberts Profile Picture

broberts 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans