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 :
Small and medium business | Business Central, N...
Suggested Answer

About SETFILTER function and Option record variables

(0) ShareShare
ReportReport
Posted on by 57

Hello

I write a function containing a local record variable lrPurchaseHeader  associated to the table 38 "Purchase Header" . The field "Document Type" is an Option field 

if I write the following I get an error

lrPurchaseHeader.SETFILTER("Document Type", lrPurchaseHeader."Document Type"::Invoice);

"Type conversion is not possible because one of the operators contains an invalid type  Text := Option"

If I write the following the compiler does not complain, but I think it's not correct.

lrPurchaseHeader.SETFILTER("Document Type", 'Invoice');

Please clarify me where is my error, thank you in advance.

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

    Hi,

    Please find the difference between SETRANGE and SETFILTER-

    SETRANGE only accepts values - a single value or a range of values(minimum, maximum) of the same type of the field on which the filter will be applied.

    Example- 
    Customer.SETRANGE("No.",10000, 20000); // Rec.SETRANGE(FieldName, LowerRange, UpperRange)

    SETFILTER accepts a string containing a filter expression.

    Example-
    Customer.SETFILTER("No.",'<>%1',20000);// all values other than 20000

    Customer.SETFILTER("No.",'>%1',20000);  //all values greater than 20000

    Customer.SETFILTER("No.",'<%1',20000);  //all values less than 20000

    In case if you need filter on Option field, Please use PurchaseHeader.SETRANGE("Document Type", PurchaseHeader."Document Type"::Invoice).

    Thanks.

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!

Congratulations to our 2025 Community Spotlights

Thanks to all of our 2025 Community Spotlight stars!

Leaderboard > Small and medium business | Business Central, NAV, RMS

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 1,958 Super User 2026 Season 1

#2
YUN ZHU Profile Picture

YUN ZHU 1,101 Super User 2026 Season 1

#3
Dhiren Nagar Profile Picture

Dhiren Nagar 959 Super User 2026 Season 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans