Thursday, 18 September 2014

Find mandatory Fied in Table



                                      Find Mandatory Field In Table

In Microsoft Dynamics Ax 2012 many table are having mandatory field. Here I would like to share how to find mandatory field in a Table.

For Example CustTable.


The below code uses DictTable and DictField classes to iterate through the table fields and it's properties.

Using these classes you can also check other properties of the fields in a table.

Step 1:-

 Go to job, Create a New job, paste following code in the job and Run the job.


 Step 2:-

static void mandatory(Args _args)

 {
    DictTable       dictTable;  //SysClass

     DictField       dictField;  //SysClass

     int             i, cust;
 
    dictTable = new DictTable(tableNum(CustTable));

     cust= dictTable.fieldCnt();   // fieldCnt- Returns the number of fields for a table//

     for (i= 1; i<=cust;i++)

     {
        dictField = new DictField(tableNum(CustTable),dictTable.fieldCnt2Id(i));

                                     //fieldCnt2Id-Returns the field ID of the field that is specified by an index//     

         if (dictField.mandatory())

         {

             info (strFmt("Field %1 is mandatory.",dictField.label()));  //Returns the label for the field//
         }
    }
   
}

Step 3:-

You can see the list of mandatory field in Infolog.



   
 

No comments:

Post a Comment