web
You’re offline. This is a read only version of the page.
close
Skip to main content
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)
  • Brad_P Profile Picture
    1,549 on at
    RE: How to change option field value in AL?

    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.

  • jdrco Profile Picture
    481 on at
    RE: How to change option field value in AL?

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

  • Verified answer
    Brad_P Profile Picture
    1,549 on at
    RE: How to change option field value in AL?

    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
    RE: How to change option field value in AL?

    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.=''

  • Suggested answer
    Brad_P Profile Picture
    1,549 on at
    RE: How to change option field value in AL?

    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();

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…

Andrés Arias – Community Spotlight

We are honored to recognize Andrés Arias as our Community Spotlight honoree for…

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

#1
Nimsara Jayathilaka. Profile Picture

Nimsara Jayathilaka. 3,180

#2
Sumit Singh Profile Picture

Sumit Singh 3,063

#3
YUN ZHU Profile Picture

YUN ZHU 2,317 Super User 2025 Season 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans