Skip to main content

Notifications

Microsoft Dynamics NAV (Archived)

IF / AND Text and Code

Posted on by Microsoft Employee

I'm writing an IF / AND Statement using these two fields

recItem."Product Group Code";  (Code)
recItem."Item Category Code"; (Text)

How can i write witghout getting an error? 

IF recItem."Item Category Code" = 'S' AND

recItem."Product Group Code" <> 'PCB' THEN BEGIN

END;

*This post is locked for comments

  • Luc van Vugt Profile Picture
    Luc van Vugt on at
    RE: IF / AND Text and Code

    Irrespective of requirements, to get this compiling make sure that the evaluation works OK, meaning that the AND operator gets on left and right side a boolean result. This means the code should be like this:

    IF (recItem."Item Category Code" = 'S') AND

        (recItem."Product Group Code" <> 'PCB')

    THEN BEGIN

    END;

    By using the brackets (recItem."Item Category Code" = 'S') is evaluated to either TRUE or FALSE. Same applies to (recItem."Product Group Code" <> 'PCB').

    If you do not use the bracket the compiler will evaluate first this part:

          'S' AND recItem."Product Group Code"

    where the logical operator AND expects two values that are Boolean and now gets two string values.

  • Verified answer
    Yogesh Kulkarni_ Profile Picture
    Yogesh Kulkarni_ 1,762 on at
    RE: IF / AND Text and Code

    Lewis, NAV will not allow you to use AND between Text and Code.

    Instead you can write like this:

    IF recItem."Item Category Code" = 'S' then begin

      if recItem."Product Group Code" <> 'PCB' THEN BEGIN

    //Do your stuff here

    END;

    END;

    -Yogesh Kulkarni
    Please verify, if you find answer helpful.

  • Suggested answer
    Amol Salvi Profile Picture
    Amol Salvi 18,694 on at
    RE: IF / AND Text and Code

    Can you elaborate more on your requirement?

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!

Community AMA December 12th

Join us as we continue to demystify the Dynamics 365 Contact Center

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,149 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans