Thursday, April 21, 2016

Insert a dynamic message bar on forms

Display a message bar on the form like the following:

...and here the code:
public static client boolean showMessageBar(FormRun formRun, str _message)
{
    #define.AddressActionBar('_gab_MessageActionBar')
    #define.MessagePane('Microsoft.Dynamics.Framework.UI.WinForms.Controls.MessagePane')
    #define.Assembly('Microsoft.Dynamics.Framework.UI.WinForms.Controls, Culture=neutral, 
                                             PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL')
    #define.MessageBar('Microsoft.Dynamics.Framework.UI.WinForms.Controls.MessageBar')

    FormManagedHostControl  messageBarHost;
    Microsoft.Dynamics.Framework.UI.WinForms.Controls.MessagePane messagePane;
    Microsoft.Dynamics.Framework.UI.WinForms.Controls.MessageBar messageBar;
    Microsoft.Dynamics.Framework.UI.WinForms.Controls.MessageBarType messageBarType;
    boolean show = true;

    formRun.lock();

    messageBarHost = formRun.design().controlName(#AddressActionBar);
    if (!messageBarHost && show)
    {
        messageBarHost = formRun.design().addControl(FormControlType::ManagedHost, 
                                                                   #AddressActionBar, null);
        // This is a bit non-obvious. addControl() will add the control at the bottom of the form.
        // MoveControl() without the second parameter will move it to be the first control.

        // This will position the message bar under any of the Action Panes
        FormRun.design().moveControl(messageBarHost.id());

        messageBarHost.assemblyName(#Assembly);
        messageBarHost.typeName(#MessagePane);
        messageBarHost.widthMode(FormWidth::ColumnWidth);
        messageBarHost.sizing(Sizing::SizeToContent);
        messagePane = messageBarHost.control();

        messageBarType =
               Microsoft.Dynamics.Framework.UI.WinForms.Controls.MessageBarType::InformationOnly;

        messageBar = new Microsoft.Dynamics.Framework.UI.WinForms.Controls.MessageBar();
        messageBar.set_Text(_message);
        messageBar.set_MessageBarType(messageBarType);

        messagePane.Add(messageBar);
    }

    if (messageBarHost)
    {
        messageBarHost.visible(show);
    }

    formRun.unLock();

    return show;
}

Tuesday, April 19, 2016

Run AIF import and export manually

Here is a job to run import and export manually, so you don’t have to wait for the batch jobs:
static void AIFImportExport(Args _args)
{
    // Inbound (import)
    new AifGatewayReceiveService().run();
    new AifInboundProcessingService().run();

    // Outbound (export)
    new AifOutboundProcessingService().run();
    new AifGatewaySendService().run();

    info("AIF import/export done");
}

Monday, April 18, 2016

Hello World!

Let's start at the beginning.
static void HelloWorld(Args _args)
{
    print 'Hello World!';
    pause;
}