Thursday, November 9, 2017

Database logging using X++ in AX 2012


Use below code to add tables into database logging using X++

The code below will add all the fields of the specific table for database logging. Just replace InventItemSalesSetup with the table you want to use for database logging. You can also put the code in a loop to select group of tables.

static void setDBLogOnTable(Args _args)
{
    TableId tableId = tableNum(InventItemSalesSetup);
    DatabaseLog log;
    SysDictTable dictT = new SysDictTable(tableId);
    SysDictField dictF;
    Set fields;
    SetEnumerator   se;


    log.logType = DatabaseLogType::Update;
    log.logTable = tableId;
    fields = dictT.fields(false,false,true);
    se = fields.getEnumerator();
    while (se.moveNext())
    {
        dictF = se.current();

        log.logField = dictF.id();
        log.insert();
        info(strFmt("Adding field %1", dictF.name()));
    }
    SysFlushDatabaselogSetup::main();
}

1 comment: