How To Insert Record Dynamically in AX 2012

Description:-

The xRecord .insert method generates values for RecId and system fields, and then inserts the contents of the buffer into the database. 

The method operated as follows:
  1. Only the specified columns of those rows selected by the query are inserted into the named table.
  2. The columns of the table being copied from and those of the table being copied to must be type compatible.
  3. If the columns of both tables match in type and order, the column-list may be omitted from the insert clause.
The insert method updates one record at a time. To insert multiple records at a time, use array inserts, insert_recordset, or RecordSortedList.insertDatabase. 

To override the behavior of the insert method, use the doInsert method.

Create Job from AOT
  • In the AOT, click Job.
  • Right-click the Job node, and then select New Job.
Step 1: Now Create Job And Run to Insert Record in A_Studnet Table.


Code:-

static void InsertMethod(Args _args)
{
    A_Student _Student;
    // Initialize the table variable
    _Student.initValue();
    // Write some values to the table variable
    _Student.Student_ID = "CT_017";
    _Student.Student_Name = "JagPratap";
    _Student.CustAccount = '1120';
    // Check if all values are legal and if so,
    // insert the values of the table variable into a record in the table
    if (_Student.validateWrite())
    {
        _Student.insert();
        info(strFmt("Student ID - %1 Has Been Inserted",_Student.Student_ID));
    }
    else
    {
        info(strFmt("Student ID - %1 Has Already Been Inserted",_Student.Student_ID));
    }
}


Related Posts

Previous
Next Post »

Thanks for comments.....