Wednesday, November 30, 2011

Hiding a data member attribute from dialogs

When you use data contracts with for example the new Business Oprations Framework (BOF), it is smart that AX will generate the dialog for you. But what if you have a field in the data contract that you don't want exposed in the dialog?

Well, use the SysOperationControlVisibilityAttribute:
[DataMemberAttribute, SysOperationControlVisibilityAttribute(false)]
public int parmIntProperty(int _parmIntProperty = parmIntProperty)
    parmIntProperty = _parmIntProperty;

    return parmIntProperty;

Monday, November 28, 2011

Create ZIP files from AX

I recently had to write a solution to create ZIP files from within AX 2012. Apparently such functionality is not very well implemented in standard .NET.

But the free DotNetZip .NET library works like a charm. Here's a link to the library on CodePlex:

Friday, November 4, 2011

Call a BOF service with a caller record

If you need to call a Business Operations Framework (BOF) service with a caller record, like you'd often do for a RunBase job, you must create a custom SysOperationServiceController to get the record argument passes from the service controller to an applicable data contract.

A good example from standard AX can found in the PurchFinalizeServiceController class.

Another example can be found here:

Print images directly from AX without user interaction

I have written one other post on doing this by calling WinApi::ShellExecute directly, but here is a more elaborate sample using .NET.

The sample prints an image (in this case a TIFF image) to your default printer without prompting first. You need to add a reference to System.Printing in AX to use the sample.

static void PrintImage(Args _args)
    System.Printing.PrintServer         localPrintServer    = new System.Printing.LocalPrintServer();
    System.Printing.PrintQueue          printQueue          = System.Printing.LocalPrintServer::GetDefaultPrintQueue();
    System.Diagnostics.Process          printProcess        = new System.Diagnostics.Process();
    System.Diagnostics.ProcessStartInfo processStartInfo;
    str                                 arguments;
    Filename                            fileName            = @'C:\TESTFILE.TIF';

    processStartInfo = printProcess.get_StartInfo();


    arguments  = @'C:\WINDOWS\System32\shimgvw.dll,ImageView_PrintTo /pt ';
    arguments += @'"';
    arguments += filename;
    arguments += @'" ';
    arguments += @'"';
    arguments += ClrInterop::getAnyTypeForObject(localPrintServer.get_Name()) + @'\' + ClrInterop::getAnyTypeForObject(printQueue.get_Name());
    arguments += @'" ';
    arguments += @'"%3" "%4"';