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 Issue

(0) ShareShare
ReportReport
Posted on by

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

I have the same question (0)
  • Verified answer
    Community Member Profile Picture
    on at

    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;

  • Verified answer
    Mohana Yadav Profile Picture
    61,005 Super User 2025 Season 2 on at

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

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)

#1
HoangNam Profile Picture

HoangNam 7

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans