Tuesday, January 26, 2016

AX 7 - Technical Insights

AX 7 is impending with a radical technical and structural change in the world of Microsoft ERP, Dynamics AX, in contrast to what we got in current version AX 2012. This is a soft indication to all developers to get ready to adopt this change nippily. There is a lot to learn on AX 7 development while supporting\working with current versions of Dynamics AX :(

Back to file system; Yes, with AX 7 we are back to file system. Any change (technical) we make in application is saved into file (XML file) at your disk.

Before we talk about the main artefacts involved in AX 7 development and the approach we will be using while developing in AX 7 world. Let's put some glance on Development environment how will it looks like, what we (developer) will have in our DEV box.



Visual Studio will be used for all development stuff; MS developed visual studio extensions using standard Visual Studio extensions to enable the development of X++ code and AX 7 metadata in Visual Studio. 

Metadata API that communicate from visual studio with the XML files that are the source code on disk. Your source and metadata are the set of XML files now. Visual Studio user interface communicates with them with an API called Metadata API. 

Build from Visual Studio: When you build from Visual Studio, it compiles into assemblies and other binaries that runtime uses and during this whole process you are working against files. At this point in time there is no need for AOS to be running during design and compilation. 

Debug: Use standard visual studio paradigms to run and debug the code with F5 and Ctrl F5.

Runtime: It is the AOS and batch manager service which are running locally into your DEV box, the AOS is actually a web service in IIS.

Database: This is a standard SQL server database in your box, 

Deployment Package: It is a major change in AX 7 and I will post more in my future posts. 
For now just to understand how it works, let's assume you have completed the development or a stage of development of a certain task into your Development box and now wan to move these changes to Production. You will need to create a package (your changes) what its called Deployment Package. These can be created onto your development box and also can be created on your build automation box. 

These Deployment Packages are compiled binary versions of your models and packages that can be deployed on the cloud. The cloud can be a test, UAT or production environment. 

Monday, January 11, 2016

AX 2012: File existance check

Multiple ways to check file existance in AX 2012;

Client side check, does not work with batch job

WinAPI::fileExists(_fileName);

Server side check which works for run base batch too

public boolean getFileExists(filepath _fileName)
{
   System.IO.FileInfo   fileInfo;
   new InteropPermission(InteropKind::ClrInterop).assert();
   fileInfo = new System.IO.FileInfo(_fileName);
   return fileInfo.get_Exists();

}

Saturday, January 9, 2016

AX 2012 - How to retrieve meeting (appointment) status from Outlook

Microsoft Dynamics AX 2012 provides a very convenient way to synchronize outlook tasks, contacts and appointments back into AX. 

MSDN topics describe the integration in details.
https://technet.microsoft.com/en-us/library/aa498242.aspx
https://technet.microsoft.com/en-us/library/gg230659.aspx

Let's discuss the main motive of this post; How can you retrieve the meeting (appointment) status from outlook back to AX 2012.

Before I show you where and what code need to add or change, I will show the existing functionality how it works.

Go to Home > Periodic > Microsoft outlook synchronization > Synchronize


Here you can see, be default it tries to sync Contacts, Tasks and Appointments within provided date range. I will focus on Appointments for this post and sync Appointments only,



Let's assume I have following meeting (appointment) response in my outlook, remember it was a meeting invitation which I sent from AX and now I have their responses back into my outllook.

For below email the response is Accepted.



Upon Sync Appointments it creates Activities in AX and can be access from Home > Common > Activities > All activities.



The last (right most) column is showing the meeting response, AX default functionality (Sync process) does not bring this meeting response back into AX. Here is the code change which needs to plug in into existing class to achieve this function.

Class: SmmOutlookSync_Appointment
Method: synchronizeAppointmentsOutlookToAxapta()



This method is retreiving the meeting status;

// Faisal.F, read meeting response;
// Accepted = 3; Tentative = 2; Declined = 4 [based on macro smmMSOutlook2002ObjectModelConstants]
private str FCM_getMeetingResponse(COM  _outlookItem)
{
    COM     recip, recips;
    str     meetingStatus;

    if ( _outlookItem.Recipients() != null)
    {
        recips = outlookItem.Recipients();
        if (recips.Count() >= 1)
        {
            recip = recips.Item(1);

            switch(recip.MeetingResponseStatus())
            {
                case 2:
                    meetingStatus = "Tentative";
                    break;

                case 3:
                    meetingStatus = "Accepted";
                    break;

                case 4:
                    meetingStatus = "Declined";
                    break;

                default:
                    meetingStatus = "None";
                    break;
            }
        }
    }
    return meetingStatus;   
}

Tuesday, January 5, 2016

Calling/Opening AX form through X++

Sample piece of code to open AX form through X++

static void OpenForm_ThroughCode(Args _args)
{
    Args                            args;
    Object                          formRun;

    // open form
    args = new Args();
    args.name(formstr(FormName));
    formRun = classfactory.formRunClass(args);
    formRun.init();
    formRun.run();
    formRun.wait();
}

If you want to pass a record to open a form

args = new Args();
args.record(ProjTable::find('PR00001'));
args.name(formstr(FormName));
formRun = classfactory.formRunClass(args);
formRun.init();
formRun.run();

formRun.wait();

How to retrieve these args on caller form's init()

public void init()
{
    ProjTable   projTableLocal;   
    super();   
    projTableLocal = element.args().record();   
}

Saturday, January 2, 2016

How to implement Runbase form in AX

Today I had a requirement that allow users to run Outlook synchronization process in batch rather sync it manually using out of the box functionality. Let's have a look on existing functionality and then extend it to achieve the requirement of running it in batch.

Existing functionality in AX

Home> Periodic > Synchronize [AOT form name is smmOutlookSyncrhonization]

As you can see someone has to manually sync outlook emails to AX acvitities or viceversa.

Extended functionality in AX

Let's implement this functionality in batch so users can set recurrence the Sync.

Create a new class;
class SyncOutLookEmails_RunbaseForm extends RunBaseBatch
{
    // Packed
    TransDate            testDate; // I am using this variable for own testing purpose
    #define.CurrentVersion(2)
    #define.Version1(2)
    #localmacro.CurrentList
        testDate
    #endmacro

}
public Object dialog()
{
    DialogRunbase   dialog = Dialog::newFormnameRunbase(formstr(smmOutlookSyncrhonization),this);
;
    return dialog;
}
public boolean getFromDialog()
{
    boolean ret;
    ret = super();
    return ret;

}
protected void new()
{
    super();
}
public container pack()
{
    return [#CurrentVersion,#CurrentList];
}
public boolean runsImpersonated()
{
    return true;

}
public boolean showQueryValues()
{
    return true;
}
public boolean unpack(container _packedClass)
{
    boolean     ret;
    Version     version = RunBase::getVersion(_packedClass);
    ;
    switch (version)
    {
        case #CurrentVersion:
            [version, #CurrentList] = _packedClass;
            ret = true;
            break;
        default:
            ret = false;
            break;
    }
    return ret;
}
server static SyncOutLookEmails_RunbaseForm construct()
{
    return new SyncOutLookEmails_RunbaseForm();
}
server static void main(Args args)
{
    SyncOutLookEmails_RunbaseForm   syncOutLookEmails_RunbaseForm = SyncOutLookEmails_RunbaseForm::construct();
    if (syncOutLookEmails_RunbaseForm.prompt())
        syncOutLookEmails_RunbaseForm.run(); 
}
Run this class by pressing F5, Ooopsss!!! it throws an error

A DialogStartGrp group is missing from the form smmOutlookSyncrhonization. In this group dialog controls are added.
This requires to add a group on the form and this has to have under a tab/tab page, let's do this;
How the current form looks in AOT


How it should look like to use it for batch class, created above.


  • Added new Tab
  • Added new Tab page
  • Added dialogStartGrp under tab page
  • Moved exisiting groups under tab page
  • Set caption "General" to tab page.
It requires few more methods at form level to make it working in batch

public class FormRun extends ObjectRun
{
    HcmWorker                   hcmWorker;
    OutlookUserSetup            outlookUserSetup;
    TransDate                   synchronizeFromDate;
    TransDate                   synchronizeToDate;
   
    SyncOutLookEmails_RunbaseForm   syncOutLookEmails_RunbaseForm;
}

public void init()
{
    synchronizeFromDate = systemdateget();
    synchronizeToDate = systemdateget();
   
    syncOutLookEmails_RunbaseForm = element.args().caller().runbase();

    super();

    if (!smmAxaptaOutlookMapping::isOutlookMappingSetupCompleted())
    {
        smmAxaptaOutlookMapping::createDefaultSetup();
    }

    // Find worker connected to the current logged ion
    hcmWorker = HcmWorker::find(HcmWorker::userId2Worker(curuserid()));

    if (hcmWorker)
    {
        outlookUserSetup = OutlookUserSetup::findByWorker(hcmWorker.RecId);
        // Calculate synchronization period based on the employee setup parameters
        activityFromDate.dateValue(systemdateget() - outlookUserSetup.SmmSynchronizeDaysBack);
        activityToDate.dateValue(systemdateget() + outlookUserSetup.SmmSynchronizeDaysForward);
    }
    else
    {
        // No employee is mapped to the current user. Set mapping in Employee option form.
        error("@SYS80637");
        element.close();
    }
}

void closeOk()
{
    DialogRunbase dialog = element.args().caller();
;
    dialog.updateServer();
    if (syncOutLookEmails_RunbaseForm.checkCloseDialog())
        super();
}

//AOSRunMode::Client
RunBase runBase()
{
    return syncOutLookEmails_RunbaseForm;
}
Run class again by pressing F5


Target achieved!!! You can run the form with batch


Happy Dax!ng !!!