Sunday 18 August 2013

Starting AX services in batch file

Just a small post regarding the starting of the AX services. I have installed AX2009 and AX2012 locally on my laptop for testing purposes. The services however take a lot of time to start up and you don't want this to be part of the bootingsequence of the laptop. So I created a bat file containing only the following lines:

@echo off

echo Starting time: %time%

net start "MSSQLSERVER"

net start "AOS50$01"

net start "AOS60$01"

echo Time finished: %time%

pause




This way you can start the services at the time you want without having to do it manually via the services. So it's a very simple and easy thing to do, but it's helpful :).

Tuesday 6 August 2013

Get Exchange Rates in Dynamics AX 2009 and 2012

Setup in Dynamics AX 2012


In DAX 2012 is now more than easy to setup the (periodic) import of Exchange Rates: 

Below is the screen with the current exchange rates [General Ledger - Setup - Currency - Currency Exchange Rates], as can be seen, it has been setup for EUR -GBP and EUR - USD and both hold one rate for the first of July. 



Create a new exchange rate provider via [GL - Setup - Currency - Configure exchange rate providers] and select one of the three default providers:


Next, import the new rates via [GL - Periodic - Import currency exchange rates]. Personally, I would uncheck "Create necessary currency pairs". It's providing new relations between currencies you haven't defined in your Exchange Rate Type. It'll only generated unwanted extra data, but hey maybe there's a good use for someone.

The forms gives you the opportunity to run this job in batch so you can update the rates whenever you prefer:


And that's it, the exchange rate is generated:



Setup in Dynamics AX 2009


Now in DAX 2009 it's a bit more difficult, there's no out of the box import available to update the rates. 
There is however a Microsoft white paper which shows how to consume a webservice which you can use to update Exchange rates, you can find the document here: http://www.microsoft.com/en-us/download/details.aspx?id=4462

The document shows how to create a button to update the exchange rate of a single currency (btw, the document mentions to add a new MenuButton, this should be a Button). The methodology however can easily be reused to run as a batch job with which you can periodically update your exchange rates in AX 2009 as well:



Friday 2 August 2013

Sync AD info with user information in AX

Recently I created this job to synchronize information from Active Directory with AX. We needed to update the e-mail address for all the employees in AX after a rebranding. 

Below you find the code, as you can see, we update the e-mail address but as an example I also update name of the employee. Also you could add the check if a user is still active in AD and if not, disable the user account in AX as well. You could extend the job to also update the email address on the employee information. 

static void JLH_SyncADwithAX(Args _args)
{
    UserInfo                            userInfo;
    xAxaptaUserManager                  axUsrMgr;
    xAxaptaUserDetails                  axUsrDet;
    Boolean                             doUpdate;
    SysUserInfo                         sysUserInfo;
    SysCompanyUserInfo                  sysCompanyUserInfo;
    #define.NewDomain("contoso.com")    // Fill in your domain
    ;

    doUpdate = Box::yesNo("Update users with new info?", DialogButton::No) == DialogButton::Yes;
    axUsrMgr = new xAxaptaUserManager();

    ttsbegin;
    setPrefix('Update AD userinfo');

    while select forupdate userInfo
    where userinfo.id != "Guest"
    {
        axUsrDet = axUsrMgr.getDomainUser(#NewDomain, userInfo.networkAlias);
        
        if(userInfo && axUsrDet)
        {
            sysUserInfo.selectForUpdate(true);
            sysUserInfo = SysUserInfo::find(userinfo.id,true);
            sysUserInfo.Email           = axUsrDet.getUserMail(0);
            userInfo.name               = axUsrDet.getUserName(0);
            userInfo.enable             = axUsrDet.isUserEnabled(0);

            if(doUpdate)
            {
                userInfo.update();
                sysUserInfo.update();
                info(strfmt("Updated for: %1, Name: %2, E-mail: %3", userInfo.Id, userInfo.name, sysUserInfo.Email));
            }
            else
            {
                info(strfmt("Not updated for: %1, Name: %2, E-mail: %3", userInfo.Id, userInfo.name, sysUserInfo.Email));
            }
        }
        else
        {
            error(strfmt("User not found: %1", userInfo.Id));
        }
    }
    ttscommit;
}