Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics NAV (Archived)

If statement error

Posted on by Microsoft Employee

I have the following code:


IF COMPANYNAME := 'Company1' THEN
     CHANGECOMPANY('Company2');
ELSE
    CHANGECOMPANY('Company1');

I am getting the following error:

6886.Capture1.PNG

Please help!

*This post is locked for comments

  • Suggested answer
    Zaid Tariq Profile Picture
    Zaid Tariq 2,266 on at
    RE: If statement error

    - Use = instead of := 
    - IF and ELSE is a single statement so you don't need yo use ; after  CHANGECOMPANY('Company2'), just use ; after  CHANGECOMPANY('Company1')

  • Verified answer
    AJAnsari Profile Picture
    AJAnsari 5,754 on at
    RE: If statement error

    Drop the : in the first line, and the ; in the second line.

    IF COMPANYNAME = 'Company1' THEN

        CHANGECOMPANY('Company2')

    ELSE

       CHANGECOMPANY('Company1');

    I hope this helps. If this answers your question, please verify by clicking “Yes” next to “Did this answer your question?”

  • Verified answer
    TonyMatt Profile Picture
    TonyMatt 510 on at
    RE: If statement error

    I dont think you can assign (:=) while using an IF statement. Rewrite the code as

    IF COMPANYNAME='Company1' THEN...

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,214 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans