Skip to main content

Notifications

Announcements

No record found.

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

  • Verified answer
    XB Profile Picture
    XB 1,869 on at
    RE: Conditional (Ternary) causes Operand types are not compatible

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

  • 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
    Martin Dráb 231,493 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

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,575 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,493 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans