Tuesday, September 17, 2013

Simple code to create table using X++

Sample job to create a table using X++

static void CreateTable(Args _args)
{
    treenode trv;

    AOTTableFieldList fieldnode;

    #AOT

    trv = treenode::findNode(#TablesPath);

    trv.AOTadd('SimpleTestTable');

    trv = trv.AOTfindChild('SimpleTestTable');

    trv.AOTcompile(1);

    trv.AOTsave();

    //filedlist = treenode::AOTfieldchild(TableName).AOTfindchild('Fileds');

    trv.AOTfindChild('SimpleTestTable');

    fieldnode = trv.AOTfirstChild();

    // adding fields

    fieldnode.addString('SimpleStringField');

    fieldnode.addReal('SimpleRealField');

    fieldnode.addInteger('SimpleIntegerField');

    fieldnode.addDate('SimpleDateField');

    fieldnode.addTime('SimpleTimeField');

    trv.AOTcompile(1);

    trv.AOTsave();

    trv.AOTcompile(1);
    
    sqlDataDictionary::Synchronize();
    
    trv.AOTrestore();

}

No comments:

Post a Comment