Security Jobs related to Dynamics AX 2012 Role Based Security

While working on security setup for one of my client, I need to do some investigations related to security objects. Resulted I have created few jobs that help me in my work. I am sharing here; it may help others also.

Finding all the Privilege related to specific menu items

static void findAllThePrivillageWithSpecificMenuItem(Args _args)
SecurityTask securityTask;
SecuritySubTask securitySubTask;
SecurityTaskEntryPoint SecurityTaskEntryPoint;
SecurableObject SecurableObject;

while select * from SecurityTaskEntryPoint
join SecurableObject
where SecurableObject.RecId == SecurityTaskEntryPoint.EntryPoint
&& SecurableObject.Name == menuitemdisplayStr(ProjGrant)

// 1. How to the find record ID of the privilege
while select * from securityTask
where securityTask.RecId == SecurityTaskEntryPoint.SecurityTask
info(strFmt(“%1,%2,%3,%4”, securityTask.AOTNAME, securityTask.Name, securityTask.Type, SecurityTaskEntryPoint.PermissionGroup));

Finding all the Duties related to specific Privilege

static void findAllTheDutiesWithSpecificPrivilage(Args _args)
SecurityTask securityTask;
SecuritySubTask securitySubTask;

// privilage name

// 1. How to the find record ID of the privilege
select firstOnly RecId from securityTask
where securityTask.AotName == #SecurityTask
&& securityTask.Type == SecurityTaskType::Privilege;

// 2. How to the find all the duties containing the specified privilege
while select SecurityTask from securitySubTask
where securitySubTask.SecuritySubTask == securityTask.RecId
select firstOnly * from securityTask
where securityTask.RecId == securitySubTask.SecurityTask;

info(strFmt(“%1,%2,%3”, securityTask.AOTNAME, securityTask.Name, securityTask.Type));

Creating a Word document with repeating in Dynamics ax 2012

In this recipe, we will create a Word document with repeating elements. For this demonstration, we will display the contents of the LedgerParameters table in a dynamically generated Word table
we need to prepare a new Word template and save it as a file named table.dotx. The template should contain one bookmark named TableName at the top, and one table beneath with a single row and two columns, as follows:

In the AOT, create a new job named CreateWordTable with the following code:
static void CreateWordTable(Args _args)
TableId tableId;
COM word;
COM documents;
COM document;
COM bookmarks;
COM bookmark;
COM tables;
COM table;
COM rows;
COM row;
COM cells;
COM cell;
COM range;
Query query;
QueryRun queryRun;
Common common;
TmpSysTableField fields;
DictField dictField;
int i;
void processBookmark(str _name, str _value)
if (!bookmarks.exists(_name))
bookmark = bookmarks.item(_name);
range = bookmark.range();
tableId = tableNum(LedgerParameters);
word = new COM(#Word);
catch (Exception::Internal)
if (word == null)
throw error(“Microsoft Word is not installed”);
documents = word.documents();
document = documents.add(#template);
bookmarks = document.bookmarks();
tables = document.tables();
table = tables.Item(1);
rows = table.rows();
query = new Query();
queryRun = new QueryRun(query);;
common = queryRun.get(tableId);
fields = TmpSysTableField::findTableFields(
null, tableId);
while select fields
dictField = new DictField(
if (dictField.isSystem())
row = rows.item(i);
cells = row.cells();
cell = cells.item(1);
range = cell.range();
cell = cells.item(2);
range = cell.range();
strFmt(‘%1’, common.(fields.FieldId)));
row = rows.add();

2. Run the job to generate the document containing a list, the LedgerParameters table
field, and their values:


Number of months between two dates in Dynamics ax 2012

Recently I got a situation where I need to calculate the number of months between 2 dates, I found a built in method in dynamics ax 2012 that can be used.

noOfIntervals = intvNo(refDate, inputDate, intvScale::Month);

intvScale enumation have two values for months

If we provide the intvScale::Month then X++ ignores the year and assumes that month is calculated within one year.

If we provide the intvScale::YearMonth then X++ calculate the number of months between different years. Consider following example.

There is another way to Calculates the difference between two dates in month units in Dynamics ax 2012 using method InfAdjValidation_MX::monthDifference(FromDate _fromDate, ToDate _toDate)

Production Data export to import in Dev/Test environment made easy by Microsoft

A new tool is release Microsoft Dynamics AX 2012 Test Data Transfer Tool (beta) on InformationSource!
This command-line tool exports data from a Microsoft Dynamics AX 2012 business database like from Production systems, and imports it into a Microsoft Dynamics AX 2012 business database in a non-production environment like Dev/Test environment.

Syntax to run this tool

 DP.exe direction directory database server
   Parameter    Default value    Description
direction    EXPORT    Specify EXPORT to export data or IMPORT to import data.
directory    The current directory    Specify the directory from which the data should be exported or to which the data should be imported.
database    AXDB    The name of the database.
server    The current computer    Specify the computer name or instance name of the SQL Server computer that is hosting the Microsoft Dynamics AX database.

Installation is also very easy

Install the Test Data Transfer Tool (beta)

Download the tool, and extract it to a local folder.
Right-click AX2012TestDataTransferTool.msi, and then click Run as administrator.
In the Setup wizard, accept the license terms, and then select the location in which to install the binaries and files for the tool. By default, the tool is installed to %Program Files%/Microsoft Dynamics AX 2012 Test Data Transfer Tool (Beta).
For complete details about the tool anyone can follow the TechNet link  Or Information Source
%d bloggers like this: