Microsoft Dynamics AX

Axapta

Trace database cleanup in an efficient way

The Trace parser is an excellent tool for troubleshooting business functionality within Microsoft Dynamics AX 2012 and Dynamics 365 for Finance and Operations. Your Trace database can quickly grow large and it does affect the tools’ performance adversely.

Removing the old trace collections one-by-one is time consuming. You could utilize a stored procedure for cleaning up your AX trace database efficiently in SQL:

-- Replace AXTrace with your database name
USE [AXTrace]
GO
 
-- Truncate transaction log to reduce size
DBCC SHRINKFILE (N'AXTrace_log' , 0, TRUNCATEONLY)
GO
 
-- Iterate through the list of traces in the database
DECLARE cur CURSOR FOR 
       SELECT [TraceId] FROM [dbo].[Traces]
 
DECLARE @Id AS int
 
OPEN cur;
FETCH NEXT FROM cur into @Id;
 
-- Remove all traces in the database with the DeleteTrace stored procedure
WHILE (@@FETCH_STATUS = 0)
BEGIN
       EXEC [dbo].[DeleteTrace] @TraceId = @Id
       FETCH NEXT FROM cur into @Id;
END
 
CLOSE cur;
DEALLOCATE cur;
 
-- Truncate transaction log to reduce size
DBCC SHRINKFILE (N'AXTrace_log' , 0, TRUNCATEONLY)
GO
By |2020-03-23T13:21:53+01:00March 31st, 2019|Categories: AX 2012, Dynamics 365 for Finance and Operations|Tags: , , , , |0 Comments

Checklist can change AX configuration keys

The other day we ran into a serious issue during our regular Production system maintenance. The Data dictionary synchronization step has started creating indexes with a DEL_ prefix on large tables such as InventTrans. We have quickly identified that AX configuration keys got changed by opening a checklist.

It turned out that some of the users had the System_Checklist security privilege assigned, and they have clicked it by accident. Standard code can add or update License configuration keys when you run the checklist.

In our case only a couple of new entries were activated, such as SysObsoleteObjects60. It has added a lot of DEL_ objects which could be easily rolled back. At another company it has done irreversible damage for inventory dimensions. You could imagine how bad the situation could get if important config keys are turned off. Synchronization would start dropping columns and entire tables.

SysConfig checklist

The quick fix was to use the Export functionality on the License configuration form from our Quality Assurance AX (daily copy of Production). Then we could import the correct configurations to Prod and revert changes by doing a Data dictionary synchronization.

Please ensure that your users only have access to security privileges they really need, to avoid unintentional damage. Remove the System_Checklist and similar features from everyone, except the administrators.

How to force running jobs server-side

We frequently write quick-fix jobs, or even some quite heavy ones which are bound to execute client-side by default. The workaround is to create an Action MenuItem pointing at the job, and setting RunOn to be Server. Then next time we need to use the code we forget about that, and it takes awfully lot to complete execution. We need to force running jobs server-side in X++ somehow, for which I do have a neat solution.

We could check if the job is running on a client or on the AOS. Then we can call the menu function to force open it server-side from code.

    // Place validation at the beginning of a job that is supposed to be server-bound
    if (!isRunningOnServer())
    {
        new MenuFunction(menuitemActionStr(YourJobActionMenuItem), MenuItemType::Action).run();
        return;
    }

Here is a quick example showing it in action:

Running Jobs server-side

This will guarantee faster execution times for database calls and resource-intensive processes, granting permissions required to be server-bound, or code that relies on reflection such as traversing AOT. We do not need to worry about remembering whether it should run on the client or not, or do not have to find the correct menu item manually. It just works!

By |2020-03-23T13:24:54+01:00September 12th, 2018|Categories: AX 2012|Tags: , , , |2 Comments

Change AOT objects without AX client

During the #MSDyn365FO upgrade code cleanup exercise for Best Practice errors one of our forms got corrupted. Compilation has caused a crash, and when I tried to reopen it then it went in an endless compile loop. I had to find a way to change AOT objects without AX client.

This could be achieved by various different solutions. One option is using the SysStartupCmd framework to import a corrected XPO with the AOTimportFile startup command. Also you could try removing the objects from the ModelElement and ModelElementData tables within the AX2012_model ModelStore DB. Another solution is to go around using the client.

I went with the last option, and used a client-less approach via talking directly to the Application Object Server through the Business Connector interface. Here is a simple PowerShell script I have implemented that uses reflection for the AOT elements, where I could access a SysTreeNode object and then delete it:

# Instantiate Business Connector proxy object and sign on
Add-Type -Path "C:\Program Files\Microsoft Dynamics AX\60\BusinessConnector\Bin\Microsoft.Dynamics.BusinessConnectorNet.dll"
$ax = new-object Microsoft.Dynamics.BusinessConnectorNet.Axapta
$ax.logon('','','','','','')

# List commands
$ax | Get-Member

# Get the incorrect form object and delete the treenode
$node = $ax.CallStaticClassMethod('SysTreeNode', 'newTreeNodePath', '\Forms\CCMOrderPadActivityMK2')
$node.Call('name')
$node.Call('delete')
Change AOT objects without AX client using Business Connector in PowerShell

This is how you could change AOT objects without AX client in a fast, safe and easy way. BC is still a very powerful way of running code on-the-fly. A similar approach was applied when we wanted to validate if AIF ports were up and running on our AOS instances earlier.

By |2020-03-23T13:37:18+01:00September 11th, 2018|Categories: AX 2012|Tags: , , , , , |0 Comments
Go to Top