Wednesday, 20 June 2012

AOT Exact Match Find in Dynamics AX 2009


Problem - Every time you search for "Address" using the find function in Dynamics AX 2009, you see every word containing the word "Address" in your search results. How do you search for an exact match?
Okay, it took me a while, but I have figured this out, it Is possible.
Adding a breakpoint to the find form shows that it uses a class called SysUtilScanSource to find your string within the AX source code.
In SysUtilScanSource.do() the method match is used to find a match against the specific source code. You can read more about match here;
The match method allows you to use expressions.
The expression you require is as follows;
:SPACE
Where SPACE is the character ' '. Sets the match to blanks, tabulations, and control characters such as Enter (new line).
For example:
match("ab: cd","ab cd"); //returns 1 
match("ab: cd","ab\ncd"); //returns 1 
match("ab: cd","ab\tcd"); //returns 1
match("ab: cd","ab cd"); //returns 0 - only the first space is matched
Therefore, you need enter the following string in the "containing text" field;
: AddressRelationship: 
Note that in the above string there are spaces in the following locations;
:SPACEAddressRelationship:SPACE 

Thursday, 16 June 2011

Microsoft Dynamics AX - Where did that Error/Warning/Info come from?

I recently had difficulty with an automated process (via the business connector) throwing a warning from deep within AX! I was working on Axapta 3.0 but I'm sure this has carried through to more recent versions.

Here are my steps to finding the source of the error;

Open the AOT
Browse to Classes
Open the Info class
Place a breakpoint on the Exception Method
Run your code (in my case this was automated so I created a test job)
The breakpoint is triggered and the debugger opens
The "Context" drop down shows the call stack.

You can use this to trace all the way back to where your code is triggering the error, warning or info.

Thursday, 27 January 2011

SQL Server Benchmark Testing & Performace Tuning - Clear Cache

When performing SQL Server benchmark testing and performance tuning, it is essential to test against a clear cache.

SQL Server stores common queries in RAM, so after the first run of tests your performance is likely to increase.

To replicate a benchmark test on a clear cache, DBAs can use the following commands;

-- Clear the data cache
DBCC DROPCLEANBUFFERS

-- Clear the stored procedure cache
DBCC FREEPROCCACHE

Thursday, 21 October 2010

C# .net Insert a Column into DataTable Source and Refresh DataGridView

Inserting rows at a particular point in a DataTable is easy, inserting columns was a bit trickier as the DataGridView didn't update or refresh its view of the DataSource;

if (dataGridView.SelectedCells.Count > 0)
{
  int selectedCellCol = dataGridView.SelectedCells[0].ColumnIndex;
  DataColumn newColumn = new DataColumn();
 
  // Set properties of the new column
  workingDataSet.Tables[0].Columns.Add(newColumn);
  newColumn.SetOrdinal(selectedCellCol);
  this.dataGridView.DataSource = null;
  this.dataGridView.DataSource = workingDataSet.Tables[0];
               
  this.dataGridView.Refresh();
 }

It seems setting the DataSource to null, followed by pointing it back at the DataTable source forced the data in the DataGridView to refresh.

Monday, 11 October 2010

Microsoft Dynamics AX Call a Static Method from C#.Net X++

Install the .Net Business Connector is installed. If not, it can be using the AX Client Setup.

Add a reference to the Business Connector DLL "C:\Program Files\Microsoft Dynamics AX\50\Client\Bin\Microsoft.Dynamics.BusinessConnectorNet.dll"

Access the method as follows;

using Connector = Microsoft.Dynamics.BusinessConnectorNet;

Connector.Axapta axInstance;
axInstance = new Connector.Axapta();axInstance.LogonAs("Username", "Domain", null, null, null, null, "AXShortcut.axc");
returnVal = (string)ax.CallStaticClassMethod("MyAXClass", "MyAXMethod", "MyArgs");

The (string)
cast of the return value could change.

Map a drive in a Windows BAT file

The following can be used to map a drive in a windows bat file without causing an error when the drive already exists;

REM SETUP MAPPED DRIVE TO Y: IF IT Y: NOT EXIST
if not exist "y:" (net use y: \\myServerName\rootFolderOfMappedDrive)

Creating an FTP Windows bat Script to Get/Put Automatically

First create a windows bat file conatining something like the following;

@echo off
REM THIS IS A COMMENT AND WILL NOT RUN
REM AUTO FTP SCRIPT
REM ANTHONY BLAKE 11/09/2010


REM myftpurl.com COULD ALSO BE THE IP OF THE FTP SITE
ftp -s:"c:\SCRIPTS\ftpAuto.txt" myftpurl.com

REM DONE!
exit

Then create your ftpAuto.txt;

myUserName
myPassword
bin
cd /DestFolder

put c:\OutboundFiles\UploadFile.csv
bye


The bat file calls the Windows FTP command and tells it to use the ftpAuto.txt script. The script changes the remote folder on the ftp site to "DestFolder" and puts the local file UploadFile.csv onto the server.

Setup a Windows Scheduled task to run at a desired interval which runs the bat file.