Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics NAV (Archived)

Setrange problem

(0) ShareShare
ReportReport
Posted on by 2,576

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

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Setrange problem

    what is the process for clearing the unposted cash book for receipts and payment?

  • Tina Menezes Profile Picture
    Tina Menezes 2,576 on at
    RE: Setrange problem

    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.

  • Luc van Vugt Profile Picture
    Luc van Vugt on at
    RE: Setrange problem

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

  • Tina Menezes Profile Picture
    Tina Menezes 2,576 on at
    RE: Setrange problem

    Thanks all.

    My issue is solved.

  • Tina Menezes Profile Picture
    Tina Menezes 2,576 on at
    RE: Setrange problem

    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.

  • Verified answer
    Amol Salvi Profile Picture
    Amol Salvi 18,694 on at
    RE: Setrange problem

    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

  • Luc van Vugt Profile Picture
    Luc van Vugt on at
    RE: Setrange problem

    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?

  • Suggested answer
    Yogesh Kulkarni_ Profile Picture
    Yogesh Kulkarni_ 1,762 on at
    RE: Setrange problem

    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.

  • Verified answer
    Mohana Yadav Profile Picture
    Mohana Yadav 60,060 Super User 2024 Season 2 on at
    RE: Setrange problem

    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.")

  • Tina Menezes Profile Picture
    Tina Menezes 2,576 on at
    RE: Setrange problem

    Error-in-setrange.PNG

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

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

Congratulations 2024 Spotlight Honorees

Kudos to all of our 2024 community stars! 🎉

Meet the Top 10 leaders for December

Congratulations to our December super stars! 🥳

Start Your Super User Journey Pt 2

Join the ranks of our community heros! 🦹

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,820 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,514 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans