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

  • Verified answer
    RE: C/AL Code OR Statement

    The In keyword works well here.

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

    Cheers

    Chris

  • Verified answer
    Tharanga Chandrasekara Profile Picture
    Tharanga Chandrasekara 23,116 on at
    RE: C/AL Code OR Statement

    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.

  • edwardl Profile Picture
    edwardl 2 on at
    RE: C/AL Code OR Statement

    Parenthesis to the rescue. Thank you Suresh.

  • Verified answer
    Suresh Kulla Profile Picture
    Suresh Kulla 44,656 on at
    RE: C/AL Code OR Statement

    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

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

Daivat Vartak – Community Spotlight

We are honored to recognize Daivat Vartak as our March 2025 Community…

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Kudos to the February Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,516 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,409 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans