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

Notifications

Announcements

No record found.

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
    237,807 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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Martin Dráb Profile Picture

Martin Dráb 4 Most Valuable Professional

#1
Priya_K Profile Picture

Priya_K 4

#3
MyDynamicsNAV Profile Picture

MyDynamicsNAV 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans