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

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Small and medium business | Business Central, N...
Answered

How to change option field value in AL?

(0) ShareShare
ReportReport
Posted on by 485

In my Sales Header table I have a custom option field "Custom Field" with members: 'yes' and 'no'. It defaults to 'yes'. I am trying to change this option field value to 'no' based on some logic I have. This is how I am going about it:

salesHeaderRec."Custom Field" := salesHeaderRec."Custom Field"::"no";

But it is not changing the option field value :(
I've also tested and made sure that I have the correct filters applied to my record so that I am changing the row I want, so that problem is not there.

I have the same question (0)
  • Suggested answer
    Brad_P Profile Picture
    1,551 on at

    It is tough to give an exact answer without additional information, but first question is Are you modifying the record after changing the value?

    salesHeaderRec.Modify();

  • jdrco Profile Picture
    485 on at

    Hi Brad_P , I have tried that but I get this error:

    The Sales Header does not exist. Identification fields and values: Document Type='Quote',No.=''

  • Verified answer
    Brad_P Profile Picture
    1,551 on at

    You need to have a Sales Header record that exists before you modify it. Set the document type and document no as appropriate.

    salesHeaderRec.Get(<document type>,<document no.>);

    salesHeaderRec."Custom Field" := salesHeaderRec."Custom Field"::no; (if this an enum you can explicitly use the type)

    salesHeaderRec.Modify();

  • jdrco Profile Picture
    485 on at

    Right now it is an Option type, should I use an enum instead?

  • Brad_P Profile Picture
    1,551 on at

    They will both work, and there are reasons to use either. One of advantages of the enum is that the values are defined once, if you need to extend or update the values you can easily.

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

Season of Sharing Community Challenge Launch!

Jump in, show your community spirit, and win prizes!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the May Top 10 Community Leaders

These are the community rock stars!

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

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 2,050 Super User 2026 Season 1

#2
YUN ZHU Profile Picture

YUN ZHU 1,441 Super User 2026 Season 1

#3
Grigorios Mavrogeorgis Profile Picture

Grigorios Mavrogeorgis 1,175 Super User 2026 Season 1

Last 30 days Overall leaderboard

Featured topics

Microsoft Training Manuals

Product updates

Dynamics 365 release plans