How to make a filed mandatory in d365 Tables

 how to make field mandatory in ax D365


1. Using a ValidateWrite method on  table;


if (!table.field)

 ret = checkfailed("the field must be filled");


2. using a ValidateWrite method on the DataSource of the table;


 table_ds.object(fieldnum(table,field1)).mandatory(true);


Sample


 public boolean validateWrite()

    {

            boolean ret;

       

            if (!this.FromDate)

                ret = checkfailed("From date must be filled");


            return ret;

    }


SalesLine Table --> ValidateWrite()


 public boolean  validateWrite()

    {

        boolean ret1;

        ret1= next validateWrite();


        if (!this.InventSiteId )

        {

                    ret1 = checkfailed("Site must be filled");

        }

       

      else  if (!this.InventLocationId  )

        {

            ret1 = checkfailed("Warehouse must be filled");

        }



        return ret1;

    }


or  form event level


 [FormEventHandler(formStr(RAR_PurgeForm), FormEventType::Initialized)]

    public static void RAR_PurgeForm_OnInitialized(xFormRun sender, FormEventArgs e)

    {

        FormDataSource purge_ds = sender.dataSource(formDataSourceStr(RAR_PurgeForm, RAR_PurgeDailyStock));


        purge_ds.object(fieldNum(RAR_PurgeDailyStock,RAR_DailyMonthly)).mandatory(true);

       

    }




Comments

Popular posts from this blog

How to Create a wizard in x++ d365

how to post trade agreement journals automatically using x++ code

X++ code to CREATE AND POST A TRADE AGREEMENT IN MICROSOFT DYNAMICS 365 in D365 F & O