Showing posts with label Events. Show all posts
Showing posts with label Events. Show all posts

Saturday, June 11, 2022

How to write to an event log from inside of a transaction

 

// to write your log from inside of another transaction
	static public void insertExtEventLogInSeparateConnection(RefRecId _lineRecId, str _guid, str _logSource, str _logStr)
    {
        ExtEventLog         log;
        UserConnection      connection;
        int                 ttsLevel    = appl.ttsLevel(); //here you can check if you are inside of a transaction
        str                 errMsg      = strFmt("Cannot add event log '%1:%2:%3'", _guid, _logSource, _logStr);
		// let's create a separate connection
        try
        {
            connection = new UserConnection();
            connection.ttsbegin();
            log.setConnection(connection);
            log.InstructionDocLineRecId = _lineRecId;
            log.TaskGUID                = _guid;
            log.LogStr                  = _logStr;
            log.LogSource               = _logSource;

            log.doInsert();
            connection.ttscommit();
        }
        catch
        {
            throw error(errMsg);
        }
        finally
        {
            if(connection)
            {
                connection.finalize();
            }
        }
    }

Friday, December 4, 2009

Flush Events related tables quickly

Quick job to delete all records from Events related tables. Inspired by this posting of Nitesh Ranjan.

static void FlushEventInbox(Args _args)
{
/*
To implement Alert functionality, Dynamics AX uses following tables:
EventParameters
EventCompanyRule
EventCUD

EventInbox
|
|- EventInboxData
|- EventRule
|
|-EventRuleData
|-EventRuleField
|-EventRuleIgnore
|-EventRuleIgnoreAggregation
|-EventRuleRel
|
|-EventRuleRelData
*/
EventRuleRelData EventRuleRelData;
EventRuleRel EventRuleRel;
EventRuleIgnoreAggregation EventRuleIgnoreAggregation;
EventRuleIgnore EventRuleIgnore;
EventRuleField EventRuleField;
EventRuleData EventRuleData;
EventRule EventRule;
EventInboxData EventInboxData;
EventInbox EventInbox;
;
if (Box::okCancel("Flush all Events related table?", DialogButton::Cancel, "Confirm deletion",
"Delete all records from: delete_from EventRuleRelData, EventRuleRel,"
+" EventRuleIgnoreAggregation, EventRuleIgnore, EventRuleField, EventRuleData,"
+" EventRule, EventInboxData, EventInbox") == DialogButton::Ok)
{
delete_from EventRuleRelData;
delete_from EventRuleRel;
delete_from EventRuleIgnoreAggregation;
delete_from EventRuleIgnore;
delete_from EventRuleField;
delete_from EventRuleData;
delete_from EventRule;
delete_from EventInboxData;
EventInbox.skipDeleteMethod(true);
EventInbox.skipDeleteActions(true);
delete_from EventInbox;
}

}