Enable database logging on groups and parameters

First I would say that I do NOT recommend to enable any database logging, unless it is business important for you, and you need to have a track of parameter changes.

But in some cases customers demand to have database logging.  I agreed and explained that it will have performance consequences, but we could do it on parameters and groups.

But I’m a type of guy that likes to create scripts to enable things.  So I wanted to share with you a small script that enables database logging on all groups and parameters.

(This script is for AX2009)

static void KHA_AddDatabaseLogging(Args _args)
{
    #AOT Name name;

    TreeNode treeNode;
    SysDictTable sysDictTable;
    DatabaseLog  DatabaseLog;
    ;
    treeNode = TreeNode::findNode(#TablesPath);
    treeNode = treeNode.AOTfirstChild();
    while (treeNode)
    {
        name = treeNode.AOTname();
        sysDictTable = SysDictTable::newTableId(treeNode.applObjectId());

        if ((sysDictTable.tableGroup() == tableGroup::Parameter ||
             sysDictTable.tableGroup() == tableGroup::Group) &&
             !sysDictTable.isMap() &&
             !sysDictTable.isTmp() &&
             !sysDictTable.isView() &&
             sysDictTable.enabled())
        {
            select firstonly DatabaseLog where DatabaseLog.logTable == sysDictTable.id();
            
            if (!DatabaseLog)
            {
                DatabaseLog.domainId = "Admin";
                DatabaseLog.logType  = DatabaseLogType::Update;
                DatabaseLog.logTable = sysDictTable.id();
                DatabaseLog.logField = 0;
                DatabaseLog.insert();
            }
            info(strfmt("Databaselogging enabled on %1",sysDictTable.name()));
        }
        treeNode = treeNode.AOTnextSibling();
    }
}

Advertisements

4 thoughts on “Enable database logging on groups and parameters

  1. You need to execute “SysFlushDatabaseLogSetup::main();” after insertion manually databaselog setup if you want that logging start directly. Otherwise, you must restart AOS to flush cache.

    Like

  2. Pingback: Enable database logging on groups and parameters | Dynamics Ax 2009

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s