Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics AX (Archived)

X++ Code for if condition

Posted on by

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

  • Suggested answer
    Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: X++ Code for if condition

    Hi,

        Just declare your table with different buffer name like PurchReqLineLoc and assign this buffer at your error line instead of  PurchReqLine.

         And your condition is wrong here, I think your going to edit Unit of measurement.

    Then you need write UOM field inside the if condition like,

        If(PurchReqLine.ItemId == "PR-FGS-00-0001")

    {

        PurchUnitOfMeasurment.AllowEdit(True);

    }

    Can i know why you want to use particular ItemId using to edit that UOM field ?

    Thanks

    Suresh

  • Suggested answer
    Pravasti AK Profile Picture
    Pravasti AK 2,985 on at
    RE: X++ Code for if condition

    Varaible PurchReqLine has not been declared

    Soln:

    See the name of your DataSource; Take that name and use that

  • neethukbabu Profile Picture
    neethukbabu on at
    RE: X++ Code for if condition

    Hi Zain,

    Thank You so much. It is working now.

    Regards,

    Neethu K B

  • Verified answer
    Zain Bokhari Profile Picture
    Zain Bokhari 3,208 on at
    RE: X++ Code for if condition

    try

    if( this.ItemID == "XX-XX-XXXXX" )

    since you are doing it on the table level and not form level.

  • neethukbabu Profile Picture
    neethukbabu on at
    RE: X++ Code for if condition

    3580.error.png

  • neethukbabu Profile Picture
    neethukbabu on at
    RE: X++ Code for if condition

    hi,

    Throwing error. Variable PurchReqLine has not been declared.

    Regards,

    Neethu K B

  • Suggested answer
    Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: X++ Code for if condition

    Hi,

         If(PurchReqLine.ItemId == "PR-FGS-00-0001")

    {

    Info("What you want check here");

    }

    OR

    If(PurchReqLine.ItemId Like "PR-FGS-00-0001")

    {

    Info("What you want check here");

    }

    Thanks

    Suresh

  • Suggested answer
    Zain Bokhari Profile Picture
    Zain Bokhari 3,208 on at
    RE: X++ Code for if condition

    .if ( PurchReqLine.ItemId == "XX-XX-XXXX" )

    this should work.

  • neethukbabu Profile Picture
    neethukbabu on at
    RE: X++ Code for if condition

    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

  • neethukbabu Profile Picture
    neethukbabu on at
    RE: X++ Code for if condition

    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

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

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,214 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans