web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

X++ Code for if condition

(0) ShareShare
ReportReport
Posted on by 6

Hi All,

I would like to write if condition in X++ language.

if one field value is equal to "Some string" then its true part.

I dont know how to take the field value

In VBA, we can write like if(field.value="String value")then true part..

Anybody can help me.

Regards,

Neethu K B

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Community Member Profile Picture
    on at

    Hi,

        You can write like operator for your string value or also you can use field.value="String value" as you mentioned.

    Thanks

    Suresh

  • Suggested answer
    Pravasti AK Profile Picture
    2,985 on at

    Hi,

    set autodeclare property of the second field to true. then in your code do

    mySecondField.value(myTable.firstField)

  • neethukbabu Profile Picture
    6 on at

    Hi Suresh,

    It is throwing error. variable not declared. It is taking field as variable.

    Actually i have one product id, i want to check if that product id equal to "PR-FGS-etc"

    Regards,

    Neethu K B

  • neethukbabu Profile Picture
    6 on at

    Hi Kavitha,

    AUtodeclare?why we doing like this?

    I didnt get you

    Regards,

    Neethu K B

  • Suggested answer
    Community Member Profile Picture
    on at

    Hi,

         If you want to check the string value using field, then in design you need to change auto declaration property to yes as Kavitha said.

    STREDT.JPG

    If I'm thinking wrong solution, please explain your question bit more.

    Thanks

    Suresh

  • neethukbabu Profile Picture
    6 on at

    Hi Suresh,

    I want to check one field value in AX with one constant string value

    For eg:  if itemvalue=="constant-string". In this itemvalue from AX, constant-string i know.

    Regards,

    Neethu

  • Martin Dráb Profile Picture
    239,084 Most Valuable Professional on at

    You didn't provide any context, so it's hard to guess what should be the right name of the variable. Nevertheless you're also using a wrong operator: '=' is for assignments, while you want comparison, which is done by '=='.

    As you've already found, other language use different syntax than VBA, therefore you have to first learn how to use them. Read X++ Language Programming Guide on MSDN, for instance.

  • Zain Bokhari Profile Picture
    3,208 Moderator on at

    Where are you trying to add this code? On a form? If so where are you selecting your value from? is it just a form level field or it comes from the form data source?

    We can't answer your question if we don't know where you are trying to add the condition and where is the field that you want to compare. Please elaborate.

  • neethukbabu Profile Picture
    6 on at

    3058.ax.png

    Hi Martin,

    This is Purchase Requisition Lines screenshot. TableName id PurchReqLine and field name is ItemID in database

    i would like to check if(itemID.value=="PR-FGS-00-0001") then condition. But this is not working. Error is showing.

    Regards,

    Neethu K B

  • neethukbabu Profile Picture
    6 on at

    Hi Zain,

    I am making changes in methods : allowfieldedit under PurchReqLine table in DB.

    Actually i want to make one field editable. I am able to do it without condition. But i want it for one particular condition.

    Regards,

    Neethu K B

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the March Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Basit Profile Picture

Basit 1

#1
GL-01081504-0 Profile Picture

GL-01081504-0 1

#1
Roya Profile Picture

Roya 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans