Approving Multiple Time sheet through workflow in AX 2012.

Hello Experts, It’s been a while, I posted my last post, today I got some good stuff to share on Time sheet approval process using Workflow in AX 2012.
Standard AX doesn’t allow multiple time sheet approval rather one time sheet at once using workflow and same can be achieved through an Auto approval process which can be set at Project management & Accounting workflow parameters.

I created an Action menu – item named “Mass Timesheet Approval”  which approves multiple timesheets using workflow at once, which is not available in the standard AX in on TSTimesheetsApprovalListPage.


In the TSTimesheetsApprovalListPage, it does not have multi-select control available at the grid. so, customization is required, but when you select multiple time sheets in grid, action button gets disabled.


To allow multi-selection of Time sheet and approved at once, I created button shown in below image, which allow multiple approval of time sheet using workflow.

Here is a code for approving multiple multiple through workflow.

Code change

Happy DaXing….


Email sending to customer/vendor using built-in functionality in ax 2012

Hello everyone,

I come up with good stuff which emphasis on how to setup Email configuration, sending the message with an attachment in ax 2012. I will elaborate on Tables, Form navigation, and classes involved in this process.

Important tables involved in configuration message body, message sender, message, etc.

1. SysEmailParameters
// configure the SMTP port no, SMTP relay server name, attachment path, and max attachment allowed.
2. SysEmailTable
//contains the email template such as sender name, sender email address, Default language.
3. SysEmailMessageTable
//Contains subject, message body and layouts such as HTML and XLST.
4. SysOutgoingEmailTable
//contains history of messages sends, senders, receiver, priority, status, etc
5. SysOutgoingEmailData
//contains history os messages with attachment, file name, extension and latest change date.

Form navigation for Email Template is as follows:

Organisation Admin -> Setup -> Email Templates (used to configure email template)


E-mail message Form is the menu item where you can edit message body.


Form navigation for Email sending status is as follows:

System administration -> Periodic -> Email processing -> Email sending status

Here, messages setup in queue in the waiting status and has to be cleared by running E-mail distributor- General batch job.


Form navigation for E-mail distributor-General batch is as follows:

System administration -> Inquires-> Batch jobs -> Batch jobs. (This has to be in the waiting status otherwise messages will not be sent)


SysEmailTable has sendEmail() static method responsible for sending message takes the parameters as EmailID, default language, recipient email address, attachment, number of retries, current user id, traceable and XML data.

once the message is sent will update SysOutgoingEmailTable SysOutgoingEmailData tables where you can see messages ( body, subject, sender, recipient, attachment).

If you want the code to send the email, below is the link which is a replica of sendEmail() method of SysEmailTable and very helpful.

Send email with attachment

 Hope you liked my post.  

Till then, Happy DaXing..,

Sales and Purchase posting using FormLetterService Class using an example in AX 2012.

It’s been a long time since I blog my last post, this time, I came up with Sales and Purchase posting using FormletterService Class. This framework has been refactored/restructured/changed in Microsoft Dynamics AX 2012 to provide better support for customizations, extensibility, and performance. It is a vital concept for developers to know before they want to customize any of the below document processes while posting

  1. If it is Sales Posting then below are sub processes (documents).
    • Confirmation
    • Picking List
    • Packing Slip
    • Invoice
  2. If it is Purchase Posting then below are sub processes (documents).
    • Confirmation
    • Receipt List
    • Packing Slip
    • Invoice

The sub processes of both Sales Posting and Purchase Posting have been accomplished using FormLetterService Class.


The run method posts documents. The following code roughly shows the pattern used in the run method in the service.run_method

The class has a service operation method for each of the document types that can be posted by this service such as postSalesOrderConfirmation() method in our case as shown below.


Here, I will try to explain using Sales confirmation scenario. so, let’s starts.

When the user clicks on Sales Order Confirmation menu item results into SalesFormLetter Class->main Method.1

When any posting happens, it must go through following steps.

Create Parm data which populates on SalesEditLines Form in our case which accomplished using SalesFormLetterParmDataConfirm extended by SalesFormLetterParmData which is extended by FormLetterParmData Class extended by FormLetterServiceController class create data in SalesParmTable, SalesParmSubTable, and SalesParmLine Tables.

When you press OK button in SalesEditLines Form, it takes you to postSalesOrderConfirmation method of FormLetterService Class. run method FormLetterService Class takes you to SalesConfirmJournalCreate Class extended by FormLetterJournalCreate Class creating Journal data in CustConfirmJour, CustConfirmTrans and CustConfrimSalesLink Tables.

Once it created Journal data, it proceeds for Journal posting. the run method of FormLetterService class takes you to SalesCofirmJournalPost class extended by FormLetterJournalPost Class updating Journal data in CustConfirmJour, CustConfirmTrans, MarkUpTrans, InventTransOrigin Tables. The FormletterJournalPost class hierarchy can be used to post one journal, for example, updating ledger and inventory.

Once it is posted, it proceeds for journal printing. This is accomplished using SalesConfrimJournalPrint extended by FormLetterJournalPrint class. The FormletterJournalPrint class hierarchy can be used to control the printing of one or more journal documents.

The following table shows where customization should be moved to the Microsoft Dynamics AX 2012 Form Letter framework.


This set of classes had a number of functions, including the following:
1) Interaction with the posting form, such as SalesEditLines.
2) Creation and maintenance of posting data, such as records in SalesParmTable.
3) Creation of journal data, such as records in CustConfirmJour/CustConfirmTrans.
4) Validations.
5) Updating sub ledgers, such as ledger and inventory.
6) Controlling document outputs, such as printing and XML export.
7) Client/server marshaling.

Hope you like my post.

Till then, Happy DaXing.

How to Debug batch jobs and service operations in Dynamics AX 2012

All batch jobs and service operations now run in managed code (IL) and require different debugging steps.  Rather than setting breakpoints within X++, you need to set them within the IL code that corresponds to the X++ code and debug in Visual Studio.

  1. Open Visual Studio as ‘administrator’ and attach the debugger to the Ax32Serv.exe process.
  2.  Note that it may also be necessary to change the ‘Attach to’ selection to ‘Managed (v4.0) code’ and make sure “just my code” is unchecked in VS: tools->options->debugging->General
  3. Once done, open up the file you want to debug in Visual Studio. All of the X++ code is compiled into IL and can be found in the following directory after deployment: ..\Program Files\Microsoft Dynamics Ax\6.0\Server\AxaptaDev\Bin\XppIL\source\
  4. Set a breakpoint in the file you opened.
  5. Go to Ax and run the process in batch mode, or execute the service operation. This will end up hitting your breakpoint, provided you set it in the right place.

If you make some changes to X++ code and want those changes reflected in the generated IL code, you need to do generate incremental CIL which reflects in IL code.


Muhammad Afsar Khan

Thanks and Happy DaXing…

How to resolve the error while importing model store “The delete statement conflicted with the reference constraint “FK_ManifestHistoryHasCategoryId”. The conflict occured in databaes “db_name_model”, table “dbo.ModelOperationHistory”, column ‘categoryId’. The statement has been terminated..Microsoft.Dynamics.AX.Framework.Toolds.ModelManagement.PowerShell.ImportStoreCommand” in AX 2012.

Yesterday, I struggled a lot while importing model store which has thrown below error and stopped abruptly.

“The delete statement conflicted with the reference constraint “FK_ManifestHistoryHasCategoryId”. The conflict occured in databaes “db_name_model”, table “dbo.ModelOperationHistory”, column ‘categoryId’.
The statement has been terminated..Microsoft.Dynamics.AX.Framework.Toolds.ModelManagement.PowerShell.ImportStoreCommand”


when I started my R&D, I found different resolutions but best and less time consuming which I found is  I am going to share now. I tried this and works magically.

Here you go and just follow these steps.

1.  Create a temporary schema in the model store database.

2.  Import the model store file into the temporary schema.

3.  Apply the temporary schema.

Please have a glance on scripts which I executed in Management shell.

a) Create a temporary schema in the model store database and importing the file into it.

This example imports a model store to the Microsoft Dynamics AX database and associates it with a non-default schema (TemporarySchema). The new model store is not visible to Microsoft Dynamics AX until the imported model store has been applied to the default schema (dbo) by running Import-AXModelStore with the -Apply parameter. If you have AX instances more than 1, you need to supply -config parameter in script otherwise not needed. If you have conflicts then go with -IDConflict parameter either with overwrite or push, -Verbose parameter will show you objects conflicting in importing environment.

Import-AXModelStore -File “Path\filename.axmodelstore” -config: configname -schemaname TemporarySchema -Verbose -IDConflict Overwrite

b) Apply the temporary schema.

Import-AXModelStore -apply:TemporarySchema -config: configname.

Hope this helps you.

Till then Happy Daxing..

The error “Function UnitOfMeasureConverter::newFromConversionParameters has been incorrectly called.” while generating Customer/Item statistics report.

Hello Experts,

I would like to share the error below which thrown while generating Customer/Item statistics report.

“Function UnitOfMeasureConverter::newFromConversionParameters has been incorrectly called.”

First & foremost part of this resolution steps is to run the report for which month, this error has thrown, similarly, then, has to step into the week of that month, then, has to step into the day of that week, copy the date value ready in the buffer.

Now critical part of this issue comes into play, you need to filter all customer transactions in CustInvoiceTrans Table by Invoice date field and paste the copied data value in it, once it is done, check SalesUnit field has data or not for every record. Insert for the record where it is missing. Re-run report and check whether it is fixed.


Note: This issue is one of the possibilities of this error.

Till then, Happy Daxiiing..

The Active Directory domain controller name cannot be reached. Verify your permissions and network connectivity.

This error pops whenever we import user into AX and below simple steps will fix the error.

Run the following commands in Command prompt.

ipconfig flushdns
ipconfig registerdns

Restart AOS services.

Hope this will fix this error.

Thank you and keep DaXing…:)

SRSReportDataProviderPreProcessTempDB Class in Ax 2012

Hi All,

I have something to share on SRSReportDataProviderPreProcessTempDB which is robust feature for the long running report in terms of execution which I copied from different sources.

Preprocessed data providers first prepare all data and only then they call SSRS. Normally the report itself asked for data when needed and if it takes too long, a timeout will kill the execution. Preprocessing data is there to avoid this problem.

Use TempDB with SrsReportDataProviderPreProcessTempDB. Regular tables were used in a previous solution and it caused some performance issues.

Report Data Provider.

An RDP class is a X++ class that is used to access and process data for a Reporting Services report. The options for a data source type for a Microsoft Dynamics AX report are the query, business logic, and RDP. An RDP class is an appropriate data source type when the following conditions are met.

  1. You cannot query directly for the data you want to render a report.
  2. The data to be processed and displayed is from Microsoft Dynamics AX.

Preprocessing reports

SSRS uses the WCF (Windows Communication Foundation) to connect to the AOS for data access. This connection has a threshold limit and it might fail if a report takes a long time to execute. The report server execution waits for the RDP to process the data and return it. In the event where the RDP takes too long a time to execute the reporting, the service might fail. Preprocessing is a strategy to beat this issue. This recipe will help you understand how to enable preprocessing for any RDP report

How to do it

When a report processes a huge amount of data or is found to take considerable time during the execution, then you can decide to incorporate preprocessing. Follow these steps to enable preprocessing.

  1. Modify RDP base class:  SRSReportDataProviderBase -> SRSReportDataProviderPreProcessTempDB
  2. Update table type:  InMemory -> TempDB
  3. Perform a full compile of IL
  4. Restart the AOS
  5. Introduce Controller class to run the report
  6. Update Output Menu Item:  Report -> Controller class

These are pre-processing AX-SSRS reports. in these report user connection information is taken using method parmUserConnection()Yes, this method sets the User Connection object on the temp table(s) that are used in the RDP class to return data. As per documentation , for pre-processing RDP reports, you must set the User Connection before the tables can be used. It is a best practice to set it in the beginning of processReport() method.

Thanks for reading…

Till then Happy DaXing…

Uploading a ​file to FTP server through X++ using batch processing…

Hi experts,

I came with one more stuff related to the uploading file to FTP server which is using batch processing, there is a lot of code change difference in file uploading to FTP server manually and using batch processing.

A class object must have RunOn property as “Server” and every time you make changes to an object, you must generate CIL.

if you would like to debug your code while it is running using batch processing, you need to debug from Visual studio and attach process to it.

Here is a sample class which uploads file to FTP server using batch processing

Sample file upload to FTP server using batch processing

Please feel free to comment your errors or suggestions or if you would like to know how to debug batch jobs using visual studio.

Thant’s it from my side, thank you

Happy Daxing…

Uploading a ​file to FTP server through X++ with detail explanation.

The File Transfer Protocol (FTP) is a standard network protocol used to transfer computer files between a client and server on a computer network but in our case, transfers file from AX client to file directory present on FTP server. You can easily find the code on the web on how to upload a file to FTP through X++ code but not in detail. In this post, I will try to explain detail about each line what it does during execution. So, let’s start.

  • The file name must not have spaces and colons in it otherwise it throws error. so, below in the example

filename = File09-12-2016_11.25.59pm.CSV;//Correct
filename = File09-12-2016_11.25.59 pm.CSV;//wrong, because there is space before pm
filename = File09-12-2016_11:25:59pm.CSV;//wrong, there is colon characters between hour, minutes and seconds.

  • Make sure you must have proper file path otherwise, it throws an error.

TempPath = System.IO.Path::GetTempPath(); //Automatically creates temporary directory
TempPath += filename;//append file to TemPath without using ‘/’ backslash.

  • If you don’t want to rename file name while file uploading on FTP server, then, use below code which works perfectly. FTP server gives it own name to file

ftpFilename = “”;
request = System.Net.WebRequest::Create(new System.Uri(ftpFileName));
ftpRequest = request; //Type casting object to ftpwebrequest object
credential = new System.Net.NetworkCredential(“Uname”, “Pword”);
//FTP file UploadFileWithUniqueName represents STOU

  • If you want to rename file name while file uploading on FTP server, then use below code which works perfectly

fileNameString = YourDesiredName.extension;
//if you don’t use @”/”, will get error.
ftpFileName = “” + @”/” + fileNameString;
request = System.Net.WebRequest::Create(new System.Uri(ftpFileName));
ftpRequest = request; //Type casting object to ftpwebrequest object
credential = new System.Net.NetworkCredential(“Uname”, “Pword”);
//FTP file UploadFile represents STOR

  • If you want to rename file name while file uploading on FTP server, then disable the proxy of FTP web request.

//UploadFile is not supported through an Http proxy, disable the proxy for this request.

  • The entry point for access stream to FTP server, which generally throws error, if any one of above mentioned statements have errors, so, be careful while writing code in above mentioned statements.

requestStream = ftpRequest.GetRequestStream();

  • Don’t keep open temporary directory in file explorer from which FTP Server reads file, otherwise, it throws  timeout error.
  • Below is perfect code to upload file to FTP server, please have a glance.

Public void uploadFiletoFTPServer
System.Object request,response,credential;
System.IO.StreamReader streamReader;
System.IO.Stream requestStream;
System.Array files;
System.Net.FtpWebRequest ftpRequest;
System.Net.FtpWebResponse ftpResponse;
System.Byte[] bytes;
System.Text.Encoding getUTF8;
System.Exception sysException;
Str 120 TempPath,executedate;
str timeinstr,nextFile;
Commaio file;
container line;
Filename filepath,fileType,fileNameString,ftpFileName,fileName;

//removed spaces and colons because of FTP protocol voilation and throws error
timeinstr = time2str(timeNow(),DateSeparator::Dot,DateSeparator::Dot);
timeinstr = strRem(timeinstr,” “);

new InteropPermission(InteropKind::ClrInterop).assert();
//part of filename
executedate = date2Str(today(),213,DateDay::Digits2,

TempPath = System.IO.Path::GetTempPath();
//complete filename with full path
TempPath += “mydesiredname”+executedate;
if (TempPath == ”)
error(“Please set up the location for export file.”);

line = [“Microsoft”,”Dynamics”,”AX”,”7.0″,”ERP”];
file = null;

// reading filepath, filname and filetype in container
[filepath, filename, fileType] = fileNameSplit(TempPath);
ftpFileName = “” + @”/” + fileNameString;
//reading file in stream buffer
streamReader = new System.IO.StreamReader(TempPath);
//Encode characters and get buffer in array of bytes, then close stream buffer
getUTF8 = System.Text.Encoding::get_UTF8();
bytes = getUTF8.GetBytes(streamReader.ReadToEnd());
// little workaround to get around the casting in .NET
request = System.Net.WebRequest::Create(new System.Uri(ftpFileName));
ftpRequest = request; //Type casting object to ftpwebrequest object
credential = new System.Net.NetworkCredential(“Uname”, “Pword”);
//FTP file UploadFile represents STOR
//UploadFile is not supported through an Http proxy, disable the proxy for this request.
//entry point for ftp server
requestStream = ftpRequest.GetRequestStream();
response = ftpRequest.GetResponse();
ftpResponse = response;//Type casting object to ftpwebresponse object
//Delete file from Temporary directory once it is uploaded to FTP server successfully.
if(ftpResponse != null)
sysException = CLRInterop::getLastException();



Hope you find my post as comprehensive and please feel free to comment below with your errors in code if you have any, I will try to figure and let you know.

Thanks and Happy DaXing..,