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 :
Microsoft Dynamics AX (Archived)

Conditional (Ternary) causes Operand types are not compatible

(0) ShareShare
ReportReport
Posted on by

container conResult;
str segmentNameToCheck;

segmentValueToCheck = conPeek(conResult, 1) ? conPeek(conResult, 2) : "";


The string empty causes a Warning of "Operand types are not compatible with the operator. However, I have a string on one side of = and "" on the other and do not know how to prevent the warning from being thrown.

*This post is locked for comments

I have the same question (0)
  • Verified answer
    XB Profile Picture
    1,875 on at
    RE: Conditional (Ternary) causes Operand types are not compatible

    Because values to return have to be of the same type.

  • Community Member Profile Picture
    on at
    RE: Conditional (Ternary) causes Operand types are not compatible

    conPeek Function [AX 2012] states that The conPeek function automatically converts the peeked item into the expected return type. Strings can automatically be converted into integers and real numbers, and vice versa. https://msdn.microsoft.com/en-us/library/aa618978.aspx 

    The warning alludes to the "" being the issue. The function gets a Boolean from position 1 and a string from position 2 of the container. If false, then use an empty string. I thus get the warning.

    This gives no warning

    segmentValueToCheck          = "";
    if (conPeek(conResult, 1))
    {
       segmentValueToCheck = conPeek(conResult, 2);  
    }

    Why does conditional (ternary) cause the warning?

  • Martin Dráb Profile Picture
    235,800 Most Valuable Professional on at
    RE: Conditional (Ternary) causes Operand types are not compatible with the operator when using a string empty in X++.

    Put your conPeek() results to variables. You'll likely find that one of them doesn't have the type you expect.

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…

Mansi Soni – Community Spotlight

We are honored to recognize Mansi Soni as our August 2025 Community…

Congratulations to the July Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Syed Haris Shah Profile Picture

Syed Haris Shah 9

#2
Mea_ Profile Picture

Mea_ 4

#3
KP-31070522-0 Profile Picture

KP-31070522-0 3

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans