Sunday, 27 October 2013

Sending Email in AX 2012

static void SendEmail(Args _args)
SysEmailParameters parameters = SysEmailParameters::find();
SMTPRelayServerName relayServer;
SMTPPortNumber portNumber;
SMTPUserName userName;
SMTPPassword password;
Str1260 subject,body;
InteropPermission interopPermission;
SysMailer mailer;
System.Exception e;

FileName                        fileName;

if (parameters.SMTPRelayServerName)
relayServer = parameters.SMTPRelayServerName;
relayServer = parameters.SMTPServerIPAddress;
portNumber = parameters.SMTPPortNumber;
userName = parameters.SMTPUserName;
password = SysEmailParameters::password();
subject = "Subject line for the email";
body = "<B>Body of the email</B>";

    //fileName       = WinAPI::deleteFile("C:\\Users\\jagadis\\Desktop\\Hello.Txt");

WinAPI::createFile("C:\\Expat Import\\Hello1.Txt");

interopPermission = new InteropPermission(InteropKind::ComInterop);
mailer = new SysMailer();
mailer.SMTPRelayServer(relayServer,portNumber,userName,password, parameters.NTLM);
//instantiate email

mailer.attachments().add("C:\\Expat Import\\Hello.Txt");

info("Email has been send!");
catch (Exception::CLRError)

e = ClrInterop::getLastException();

while (e)


e = e.get_InnerException();
info ("Failed to Send Email some Error occure");


Wednesday, 23 October 2013

Number to Word

public static string NumberToWords(int number)
    if (number == 0)
        return "zero";

    if (number < 0)
        return "minus " + NumberToWords(Math.Abs(number));

    string words = "";

    if ((number / 1000000) > 0)
        words += NumberToWords(number / 1000000) + " million ";
        number %= 1000000;

    if ((number / 1000) > 0)
        words += NumberToWords(number / 1000) + " thousand ";
        number %= 1000;

    if ((number / 100) > 0)
        words += NumberToWords(number / 100) + " hundred ";
        number %= 100;

    if (number > 0)
        if (words != "")
            words += "and ";

        var unitsMap = new[] { "zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen" };
        var tensMap = new[] { "zero", "ten", "twenty", "thirty", "forty", "fifty", "sixty", "seventy", "eighty", "ninety" };

        if (number < 20)
            words += unitsMap[number];
            words += tensMap[number / 10];
            if ((number % 10) > 0)
                words += "-" + unitsMap[number % 10];

    return words;

Dynamics AX 2012 Excel Add-in - Issues

Dynamics AX 2012 Excel Add-in - Issues and Solutions (Method UpdateRecIdVisibility not found)

Dynamics AX 2012 Excel Add-in – Issues and Solutions (Method not found: ‘Void Microsoft.Dynamics.AX.Framework.OfficeAddin.DataSourceContainer.UpdateRecIdVisibility(Boolean))
Purpose: The purpose of this document is to outline some issues you may encounter when using Dynamics AX 2012 Excel Add-in for import of data and provide solutions to resolve them.
Issue: ‘Method not found: ‘Void Microsoft.Dynamics.AX.Framework.OfficeAddin.DataSourceContainer.UpdateRecIdVisibility(Boolean)’
Reason: After you initially install Microsoft Dynamics AX 2012 R2 Office Add-ins and then install Microsoft Dynamics AX 2012 R2 CU1 the old Microsoft Dynamics AX 2012 R2 DLLs related to Office Add-ins may still be present in the file system. The system uses old Microsoft Dynamics AX 2012 R2 DLLs related to Office Add-ins DLLs which causes this issue
Dynamics AX Error
For example, on the latest (as of today, April 24, 2013) Microsoft Dynamics AX 2012 R2 CU1 Demo VM this error occurs when you launch Excel 2013, define connection Options and then try to Add Table or Add Data  
Please note that Microsoft Dynamics AX 212 R2 CU1 build number is 6.2.1000.156
In fact if you look for UpdateRecIdVisibility method in Microsoft Dynamics AX 2012 R2 CU1 Microsoft.Dynamics.AX.Framework.OfficeAddin.dll assembly you will be able to find it there
So the real problem is in the fact that the system uses old Microsoft Dynamics AX 2012 R2 Microsoft.Dynamics.AX.Framework.OfficeAddin.dll assembly instead of new one
Please note that Microsoft Dynamics AX 212 R2 build number is
And if you check the version of Microsoft.Dynamics.AX.Framework.OfficeAddin.dll assembly
in C:\Windows\Microsoft.NET\assembly\GAC_MSIL folder
You will see that it’s which corresponds to Microsoft Dynamics AX 2012 R2
Solution: Please delete highlighted above Microsoft.Dynamics.AX.Framework.Office.Addin folders in C:\Windows\Microsoft.NET\assembly\GAC_MSIL folder to get rid of old versions of DLLs   
If you get a message that Microsoft.Dynamics.AX.Framework.Office.Addin.dll is being used by another process when you try to delete it, please stop Microsoft Dynamics AX AOS and try again
Result: As the result you will be able to Add Tables and Add Data in Excel workbook
Add Tables
Field Chooser

No device error in Dynamics Ax.

Recently I wanted to avoid that the infolog pops-up with several

'No Device'

error messages when opening the AX client with ConfigKey Telephony Integration enabled.
This error message is caused by the ActiveX component for the phone integration on form smmPhone which returns an error for each phone device which is offline.

I did the following code changes to prevent the error message:


void onEvent_TapiError(int errorCode)
    if(errorCode != -2147483582) // Avoid 'No Device' Error

This error comes as a result of the Microsoft Dynamics File being unable to locate the CmxPhone.ocx File in this path: C:\Program Files\Microsoft Dynamics AX\Common

To solve this error:

1. Close Axapta

2. Copy the “smmPhone.ocx” file from this path : C:\Program Files (x86)\Microsoft Dynamics AX\Common and paste it here: C:\Program Files\Microsoft Dynamics AX\Common

3. Next, you rename the file to “CmxPhone.ocx”

4. After you do this, you open the command line (cmd) and enter in this command: regsvr32 "C:\Program Files\Microsoft Dynamics AX\Common\CmxPhone.ocx" 
(Note: This command registers the file on the system)

5. Press Enter. Open Axapta back up and the software should open without the error message popping back up.

Sunday, 6 October 2013

Visual studio configuration for AX SSRS reports

Open Visual Studio with a Specific Configuration [AX 2012]

0 out of 3 rated this helpful
Updated: February 24, 2012
Applies To: Microsoft Dynamics AX 2012 R2, Microsoft Dynamics AX 2012 Feature Pack, Microsoft Dynamics AX 2012
You can configure Visual Studio to open with a specific Microsoft Dynamics AX client configuration. This causes Application Explorer to point to the designated configuration. A configuration is a group of startup settings that are used by a client. For more information, see Manage a client configuration
To open a specific configuration, you use the /AxConfig switch with a parameter of either a configuration name or the path and file name of a configuration file (.axc file). If your configuration name or configuration file name contains spaces, be sure to enclose the parameter in quotes. If no parameter is specified, then the default configuration is used.
If you are working with reports, the Visual Studio integration uses the active local client configuration to establish the connection. Examples that require a Reporting Services configuration include deploying a report or selecting a query as a data source. To point to the correct AOS in this scenario, create a copy of the configuration file in the Visual Studio integration folder.
If you point Visual Studio to an invalid configuration or a configuration that has been deleted and then try and open it, Visual Studio will open but the Application Explorer pane will display the message AOS Disconnected.
This topic shows you how to configure Visual Studio to open with a client configuration from a shortcut or from the command line. It also describes how to set the configuration for Microsoft Dynamics AX reporting scenarios.
To complete this scenario you will need:
  • Microsoft Dynamics AX with Visual Studio Tools installed
  • Visual Studio 2010
  • At least one Microsoft Dynamics AX client configuration

To Open Visual Studio with a Specific Configuration from a Shortcut

  1. On the client computer that is running Visual Studio, open the Start menu, right-click Visual Studio 2010, and select Properties.
  2. Update the Target field and add the /AxConfig switch with either the name of the client configuration or the name of the client configuration file as shown in the following examples:
    "C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\devenv.exe" /AxConfig ContosoDev
    "C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\devenv.exe" /AxConfig z:\Config\ContosoDev.axc
    If you run the Visual Studio executable with a parameter of /?, then it will show you all the available switches you can use.
    When pointing to a configuration file, you can use a Universal Naming Convention (UNC) file location such as \\Server\Configurations\ContosoDev.axc.
  3. Click OK. When you click the Visual Studio shortcut, it opens and Application Explorer points to the specified client configuration. The name of the configuration appears at the top in the root node of Application Explorer.

To Open Visual Studio with a Specific Configuration from the Command Line

  1. You can open Visual Studio with a client configuration from the command line. To do so, click Start > Run, type cmd and then click OK.
  2. Navigate to the directory that contains the Visual Studio IDE executable, for example, C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE. Then type one of the commands shown in the previous procedure (without the quotes), for example, devenv.exe /AxConfig ContosoDev.

To Create a Specific Configuration for Reports

  • To create a configuration for Reporting Services, run the Microsoft Dynamics AX configuration utility as an administrator, and then click Manage > Save configuration as file, and give the configuration a name like Microsoft.Dynamics.AX.ReportConfiguration.axc. The file must be saved in the PrivateAssemblies folder in the Visual Studio IDE installation directory, like the following:
    C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\PrivateAssemblies.