Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics AX (Archived)

Conditional (Ternary) causes Operand types are not compatible

(0) ShareShare
ReportReport
Posted on by Microsoft Employee

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,867 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
    Community Member Microsoft Employee 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
    Martin Dráb 230,503 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

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 Verified Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,503 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans