Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics NAV (Archived)

SETRANGE Issue

Posted on by Microsoft Employee

I am trying to create a code unit to go through and delete sales quotes older than 30 days from todays date. I am having an issue with the setrange though. Checking to see if anyone knows what I am doing wrong.

TodaysDate := TODAY;

SalesHeader.SETRANGE(SalesHeader."Document Type", SalesHeader."Document Type"::Quote);

SalesHeader.SETRANGE("Order Date", TodaysDate); //it wont set range, I assume because I have no sales quotes with this date

IF SalesHeader.FINDSET THEN BEGIN

Duration := TodaysDate - SalesHeader."Document Date";

IF Duration > 30 THEN BEGIN

REPEAT

MESSAGE(SalesHeader."No."); //i will put in code to delete here after i get this to work

UNTIL SalesHeader.NEXT = 0;

END;

END;

*This post is locked for comments

  • Verified answer
    Mohana Yadav Profile Picture
    Mohana Yadav 59,139 Super User 2024 Season 2 on at
    RE: SETRANGE Issue

    becarefull with BEGIN END statement

    IF Duration > 30 THEN

          SalesLineDelete(SalesHeader."No.");

          SalesHeaderDelete(SalesHeader."No.");

    If duration is <= 30 then below line will still execute.

    SalesHeaderDelete(SalesHeader."No.");

  • Verified answer
    Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: SETRANGE Issue

    NM, I figured out what my issue was.

    SalesHeader.SETRANGE(SalesHeader."Document Type", SalesHeader."Document Type"::Quote);

    SalesHeader.SETFILTER("Document Date", '<%1', TODAY);

    IF SalesHeader.FINDSET THEN BEGIN

       REPEAT

         Duration := TODAY - SalesHeader."Document Date";

         IF Duration > 30 THEN

           SalesLineDelete(SalesHeader."No.");

           SalesHeaderDelete(SalesHeader."No.");

       UNTIL SalesHeader.NEXT = 0;

    END;

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,198 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans