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)

field must be entered

(0) ShareShare
ReportReport
Posted on by 327

hi i have a form.in that i have two fields that is PASSPORT(ENUM TYPE),and PASSPORTNUM(STRING TYPE).
PASSPORT is enum type i kept as a checkbox.i want enter some data in that so if i make passport column as yes tha means checkbox is checked then passport number must be enter with out enter it cont save.if i make checkbox no need of pasport number it should save for that i write a code in modified method in forms.but its not working any one please check that...

public void modified()
{

ITTI_EmpDetails a; //Table name
super();
select a where a.RecId==ITTI_EmpDetailsDS.RecId;

if(a.PassPort == NoYes::Yes)

ITTI_EmpDetailsDS_PassportNum.mandatory(true);


}

thank you.....

*This post is locked for comments

I have the same question (0)
  • Sohaib Cheema Profile Picture
    49,677 Super User 2026 Season 1 on at

    write your code in active() method of datasource

  • Sohaib Cheema Profile Picture
    49,677 Super User 2026 Season 1 on at

    Moreover no need to write select statement.

    you can directly refer fields such as CurrentDataSourceName.FieldName

    e.g. in your case

    if(ITTI_EmpDetailsDS.PassPort == NoYes::Yes)

    {

    //  set object mandatory

    }

    else

    {

    //let it be non mandatory

    }

  • karthik143 Profile Picture
    327 on at

    thanks mr.sohaib i tried this but not working will you please check my code...

    public int active()

    {

        int ret;

        ITTI_EmpDetails a;

       ret = super();

        if(a.PassPort == NoYes::Yes)

       {

        ITTI_EmpDetailsDS_PassportNum.mandatory(true);

       }

       else

       {

       ITTI_EmpDetailsDS_PassportNum.mandatory(false);

       }

       return ret;

    }

  • Suggested answer
    Sohaib Cheema Profile Picture
    49,677 Super User 2026 Season 1 on at

    public int active()

    {

       int ret;

       ret = super();

       if(ITTI_EmpDetails.PassPort == NoYes::Yes)

       {

    ITTI_EmpDetails_DS.object(fieldNum(ITTI_EmpDetails,PassportNum)).mandatory(true);

       }

       else

       {

    ITTI_EmpDetails_DS.object(fieldNum(ITTI_EmpDetails,PassportNum)).mandatory(false);

       }

       return ret;

    }

  • Suggested answer
    Jonathan  Halland Profile Picture
    11,310 on at

    Hi, can I suggest that this type of related field rule is normally validated on writing of the record rather than by making a datasource field mandatory. Perhaps write your checking in your Datasource's "ValidateWrite" method.

    As an example if these fields are in a grid you will get strange results. As soon as you check the checkbox the "PassportNum" field will show as mandatory on everysingle record.

  • karthik143 Profile Picture
    327 on at

    its not working mr.sohaib....if i check the check box without enter passport number its savings.....basically with out enter passport num i shouldnot be save.but its saving

  • Sohaib Cheema Profile Picture
    49,677 Super User 2026 Season 1 on at

    then write your code as suggested by Jonathan, on validateWrite(). it must validate before save.

    above code can help you at user interface level. logic would be same in validateWrite as well, only difference will  be that you will refer objects by this keyword e.g. this.FieldName ; throwing back checkFailed in case of non-valid data.

  • krishna.rao@dax Profile Picture
    3,008 on at

    As Jonathan Halland said try to write code in  Datasource's "ValidateWrite" method.

    Certainly it works.

    Have a try and let us know.

  • karthik143 Profile Picture
    327 on at

    in form data source node i have written this but its not working check my code

    public boolean validateWrite()

    {

       boolean ret;

      ITTI_EmpDetails   ITTI_EmpDetails;

       ret = super();

       if(ITTI_EmpDetails.PassPort == NoYes::Yes)

       {

       ITTI_EmpDetailsDS_ds.object(fieldNum(ITTI_EmpDetails ,PassportNum)).mandatory(true);

      }

      else

      {

    ITTI_EmpDetailsDS_ds.object(fieldNum(ITTI_EmpDetails,PassportNum)).mandatory(false);

      }

       return ret;

    }

    thanks all

  • Sohaib Cheema Profile Picture
    49,677 Super User 2026 Season 1 on at

    we are talking about Table Method validateWrite(), for sure you cannot refer fields by this keyword on form level, if you will read my previous reply you will find. kindly write your code on table level and use checkfailed to return false in case mandatory information is not provided

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
Joris dG Profile Picture

Joris dG 5

#2
Andrew Jones a1x Profile Picture

Andrew Jones a1x 2

#3
GL-01081504-0 Profile Picture

GL-01081504-0 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans