Greg On Dynamics Ax

Random thoughts about development using Dynamics AX and .Net

Archive for the ‘Extensions’ Category

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

Advertisements

Written by gregondax

July 23, 2009 at 7:00 am

Handy editor script

leave a comment »

Editor scripts can come in really handy for repetitive tasks.

Being quite a stickler for code that is nice to read, I have written an extension that makes it easy to format blocks of variable assignment or declarations into nicely formatted columns.

Take the following code, for example:

static void Example(Args _args)
{
    IntrastatParameters intrastatParameters = IntrastatParameters::find();
    SalesTable salesTable;
    NumberSeq numberSeq;
    SalesLine salesLine;
    SalesFormLetter salesFormLetter;
    ;
    numberSeq = NumberSeq::newGetNumFromCode(SalesParameters::numRefSalesId().NumberSequence);

    salesTable.SalesId = numberSeq.num();
    salesTable.TransactionCode = intrastatParameters.DefaultSalePurchase;
    salesTable.Transport = intrastatParameters.TransportModeParm;
    salesTable.Port = intrastatParameters.PortParm;
    salesTable.CustAccount = "4015";

By selecting the blocks of declarations, then choosing Scripts -> addIns -> FormatToColumnLayout, will result in the following:

static void Example(Args _args)
{
    IntrastatParameters intrastatParameters = IntrastatParameters::find();
    SalesTable          salesTable;
    NumberSeq           numberSeq;
    SalesLine           salesLine;
    SalesFormLetter     salesFormLetter;
    ;
    numberSeq = NumberSeq::newGetNumFromCode(SalesParameters::numRefSalesId().NumberSequence);

    salesTable.SalesId         = numberSeq.num();
    salesTable.TransactionCode = intrastatParameters.DefaultSalePurchase;
    salesTable.Transport       = intrastatParameters.TransportModeParm;
    salesTable.Port            = intrastatParameters.PortParm;
    salesTable.CustAccount     = "4015";

You can find more detail, including the download here at axaptapedia.

Written by gregondax

January 24, 2009 at 7:12 pm