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)

C/AL Code OR Statement

(1) ShareShare
ReportReport
Posted on by 2

Instead of having an IF...ELSE IF...ELSE... like I currently do:

IF FORMAT(AccSchedName) = 'BAL SH SUM' THEN

  PeriodText := 'As at: ' + FORMAT(EndDate)

 

ELSE IF FORMAT(AccSchedName) = 'BALANCE SH' THEN

  PeriodText := 'As at: ' + FORMAT(EndDate)

 

I want a single IF statement to cleanup my code a bit. In the other languages I know it would work like this:

IF FORMAT(AccSchedName) = 'BAL SH SUM' | 'BALANCE SH' THEN

PeriodText := 'As at: ' + FORMAT(EndDate)

Operators I have tried and gotten errors from:

|, ||, OR

*This post is locked for comments

I have the same question (0)
  • Verified answer
    Suresh Kulla Profile Picture
    50,243 Super User 2025 Season 2 on at

    Edward,

    Have you tried like this

    IF (FORMAT(AccSchedName) = 'BAL SH SUM') OR ((FORMAT(AccSchedName) = 'BALANCE SH') THEN

    PeriodText := 'As at: ' + FORMAT(EndDate)

    OR should work only difference is each statement should enclosed in separate parenthesis.

    Try this and let me know if this does not work

  • edwardl Profile Picture
    2 on at

    Parenthesis to the rescue. Thank you Suresh.

  • Verified answer
    Tharanga Chandrasekara Profile Picture
    23,118 on at

    Try with the code Suresh given.

    In NAV you need to have ( ) brackets for every condition.

    Even if you write the code in

    IF FORMAT(AccSchedName) = 'BAL SH SUM' OR FORMAT(AccSchedName) = 'BALANCE SH' THEN

    it will throw an error.

  • Verified answer
    Community Member Profile Picture
    on at

    The In keyword works well here.

    IF FORMAT(AccSchedName) IN ['BAL SH SUM', 'BALANCE SH'] THEN ...

    Cheers

    Chris

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)

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans