How to make field mandatory in ax D365

Hi,

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;
    }

Comments