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

How to change option field value in AL?

(0) ShareShare
ReportReport
Posted on by 481

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,549 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
    481 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,549 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
    481 on at

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

  • Brad_P Profile Picture
    1,549 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

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 > Small and medium business | Business Central, NAV, RMS

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 2,664

#2
YUN ZHU Profile Picture

YUN ZHU 960 Super User 2025 Season 2

#3
Jainam M. Kothari Profile Picture

Jainam M. Kothari 773 Super User 2025 Season 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans