Greg On Dynamics Ax

Random thoughts about development using Dynamics AX and .Net

Archive for the ‘.Net’ Category

X++ for .Net Developers (.Net Rocks! Interview)

leave a comment »

I recently had an interview with Carl and Richard at .Net Rocks about what .Net developers need to know about AX.

The show went live yesterday – you can check it out here: http://www.dotnetrocks.com/default.aspx?showNum=703.

Written by gregondax

October 5, 2011 at 7:41 am

Posted in .Net, x++ Language

Automated Messaging to Office Communicator (from code)

leave a comment »

A new feature introduced with Dynamics AX 2009 was integration with Office Communicator.

This enables the presence of a person/contact to be shown as part of the contact information, along with links to contact that person:

Office Communicator integration with Dynamics AX

Office Communicator integration with Dynamics AX

Selecting the link to send an instant message to a contact launches the Office Communicator client conversation:
Office Communicator Client

The following job shows how to send an instant message to a contact using Office Communicator from code:

static void UCMAExample(Args _args)
{
    AlertSender.OCS_Sender ocSender;
    ;

    try
    {
        ocSender = new AlertSender.OCS_Sender(@"sip:Administrator@contoso.com", "ax-srv-03.contoso.com",
                                                        "Administrator", @"thepassword", "contoso");
        ocSender.SendMessage("sip:Alicia@contoso.com", "Hello from AX", "Normal");
    }
    catch(Exception::CLRError)
    {
        throw error(AifUtil::getClrErrorMessage());
    }
}

To enable this you will need to install the UCMA redistributable, available as part of the UCMA SDK download:
http://www.microsoft.com/downloads/details.aspx?FamilyID=b30306e4-7dc1-44d2-9a68-9b4a6fc5c2df&displaylang=en

You will also need to modify, compile and add the AlertSender.OCS_Sender .Net reference to AX, which is available to download here:
http://www.microsoft.com/downloads/details.aspx?FamilyId=9EFC784B-E443-4441-926C-5FD405D41BD9&displaylang=en

Written by gregondax

January 18, 2010 at 9:02 am

Solving an ‘Object object has not been initialized’ runtime error

leave a comment »

If you have received the error below, and are scratching your head over the cause:

Object object not initialised error

Then the answer is to check you have called super() in your constructor. The compilation output will also display a warning to that effect:

Compile warning for not overriding super in constructor

Related notes about extending Object and initialization

Unlike C#, Object is not implicitly extended when creating a new class. You’ll need to ensure that the ‘extends object’ class declaration is included if you want to call methods declared in Object, eg:

extendsObject

Repeating the aforementioned error (and also unlike C#) the base constructor is not implicitly called in X++:

void new()
{
;
super(); //base constructor is not called implicitly
}

Written by gregondax

November 23, 2009 at 9:30 am

Spell check text box – Example of a WPF control in AX

with 2 comments

This post shows how to add ‘Microsoft Word’ like spell checking to standard AX forms, taking the label editor as an example:

Spell check control in AX

Spell check control in AX

When a word is misspelled it will underline that word red, and right-clicking will show a context menu with alternative suggestions.

The user control and xpo are both available to download, with instructions to install at axaptapedia (see link at the bottom of this post).

How it was built

The first step is to create the user control in Visual Studio 2008.

All there is to the user control is a WPF Textbox – which has spell checking built in!
All you need to do is set the SpellCheck.IsEnabled property::

<TextBox Name="textBox" SpellCheck.IsEnabled="True" Language="en-gb"></TextBox>

This user control then needs to be exposed as an ActiveX to be used in Dynamics AX. (A very helpful colleague of mine gave me some guidance on this.)

Please see this link (MSDN Tutorial: Create a Win32 Application Hosting WPF Content) for an example on how to do this.

To automatically deploy to clients

In AX, make use of the SysFileDeployer framework. To do this subclass SysFileDeploymentDLL, ensuring that you override the filename method to return the name of your library.

Also if you have developed a .Net WPF control you will need to register the library using regasm instead of regsvr32, so make sure you override (or inherit) the register and unregister methods so that regasm is used:

class SysFileDeployment_DevWpf extends SysFileDeploymentDLL
{
 #Define.regasmCommand(@'C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\RegAsm.exe')
}

public Filename filename()
{
 return 'WpfTextBoxControlLibActiveX.dll';
}

protected void register(boolean atReboot = false)
{
 ;
 WinAPI::setCurrentDirectory(this.destinationPath());
 //TODO Check regasm executable exists on client?
 WinAPI::shellExecute(#regasmCommand, strfmt('"%1" %2', this.destinationPath()+this.filename(),'/codebase'));
}

protected void unRegister()
{
 ;
 WinAPI::setCurrentDirectory(this.destinationPath());
 //TODO Check regasm executable exists on client?
 WinAPI::shellExecute(#regasmCommand, this.destinationPath()+this.filename()+' /unregister');
}

Then add your class(es) to the SysFileDeployer filesToDeploy method:

private static container filesToDeploy()
{
 ;
 return [classnum(SysFileDeployment_DevWpfMainControl), classnum(SysFileDeployment_DevWpf)];
}

Then ensure that your dll’s are shared on your server (copy them to your  %AXDIR%/50/Client/Share/Include directory on your AOS server) and either update the application version of AX, or delete the usage data for the SysFileDeployer job for each client, then each client that starts up will get the option to deploy your new libraries:

clientFileDeployment

Download the control and example xpo here from axaptapedia
The steps for installing the control into your label editor can also be found here at axaptapedia

Written by gregondax

July 23, 2009 at 7:00 am

X++ and C# Compared

leave a comment »

With the advent of Dynamics AX 2009, the need for AX developers to know .Net is increasing.

I have noticed the AX developer documentation on MSDN getting better and better, here is a section comparing X++ and C# that is well worth a read, check it out!:

X++ and C# Comparisons

Dynamics AX MSDN Developer Center – X++ and C# comparisons

Written by gregondax

June 12, 2009 at 9:00 am