Total Pageviews

Search This Blog

Wednesday, November 30, 2011

Tip - How to write to utf-8 encoding format using CommaTextIo Class

A few months back, I had written a basic post on How to export csv data from AX using CommaTextIO Class

Now, we had a requirement to output the file in utf-8 encoding format and the credit for this post goes to Super Mario (Read below to find who Super Mario is ;-) ..) for his tip which I'm sharing with you all.

Tip/Solution:

The UTF-8 encoding was achieved by using an additional parameter while calling the constructor for CommaTextIO class.The 3rd(optional) parameter is the codepage integer value. It was achieved as per below:
commaTextIo = new CommaTextIo(fileitemdata,#io_write, 65001);

65001 is the Codepage identifier for utf-8

What's interesting in Dynamics AX 2012 for UTF-8:

I was curious to know how UTF-8 is implemented in the new version of Dynamics AX 2012 and did a search at the AOT Level, found that now we have a placeholder for UTF-8 format in AOT > Macros > File
I compared the File Macro in AX 2009 and AX 2012, in AX 2009 there’s no macro for utf-8 but in AX 2012, we have a declaration for it in Macros > File
/*
UTF-8 Format
*/
#define.utf8Format (65001)

But surprisingly it's not used anywhere for e.g. if you see the EditorScripts Class in Dynamics AX 2012, it still uses the literal value 65001 and not the Macro which is defined above.
public void sendTo_file(Editor  e)
{
    Filename filename;
    TextIo io;
    int i = strFind(e.path(), '\\', strLen(e.path()), -strLen(e.path()));
    str defaultName = subStr(e.path(), i+1, strLen(e.path()));
    ;
    filename = WinAPI::getSaveFileName(0, ['Text','*.txt'], '', "@SYS56237", 'txt', defaultName );
    if (filename)
    {
        // BP deviation documented
        io = new TextIo(filename, 'W', 65001); // Write the file in UTF8
        io.write(EditorScripts::getSelectedText(e));
    }
}

I extended our current File Macro by including the following utf encoding declarations under Macros > File for our future reference.

/*
UTF Encoding Format
*/
#define.utf7Format (65000)
#define.utf8Format (65001)
#define.utf16Format (1200)
#define.utf32format (12000)
#define.usascii (20127)

Below MSDN link has the definitions of all the codepage values if you are interested.

Ok Ok... I know you have reached here and still wondering who is Super Mario .. :-) He's my boss who is a techie himself. :-)

Thursday, November 24, 2011

Tip - How to get a blank InventDimId out

Today, while writing a QueryRange, I had to pass a blank InventDimid. Initially, to make life easier ;-). I just put "BLANK".

Then, just did a bit of search and found that InventDim has a static method inventDimIdBlank which was exactly what I required. It returns "AllBlank". Many of you guys might be knowing this one, but just for the ignorant out there (including me) :-) this is a handy tip

InventDim::inventDimIdBlank()

Tip - How to Retrieve AOS Instance name in Dynamics AX via X++ Code

One of my mates asked me how to retreive AOS Instance name through code. My first impression was that it should be somewhere in the Global Class. But, soon figured out I was wrong, then I jumped into Session Class which has a static method getAOSInstance() which retreives the instance number

The requirement here was to extract the instance name. Suddenly, it striked me, that in standard AX in Administration > Online Users form, the last column shows the AOS instance name.

So, the next step was to go through AOT > Forms > SysOnlineUsers > display method getAOSInstanceName() -  here the key is serverSessions.aosId and serverSessions.Instance_Name - combination of both will give you the aos instance.

//BP Deviation documented
display ServerId getAOSInstanceName(SysServerSessions serverSessions)
{
    ServerId            sid = '';
    str                 aosId, machineName, instanceName;
    int                 pos;
    #DEFINE.ATSYMBOL('@')
    ;
    aosId = serverSessions.aosId;
    instanceName = serverSessions.Instance_Name;
    pos = strfind(aosId, #ATSYMBOL, 1, strlen(aosId));
    machineName = substr(aosId, 1, pos-1);
    sid = instanceName + '@' + machineName;
    return sid;
}

Sometimes Googling within AX helps  Njoi  ;-)








Wednesday, November 23, 2011

Tuesday, November 22, 2011

Tip - Dynamics AX Client and Run as different user in Windows 7 64 bit

I wanted to do some User Permissions testing using Dynamics AX Client with different users using Run As Option. i.e. Right-Clicking the client and then bringing up the Windows challenge dialog wherein one can put the user name and password shown below

















In previous versions of Windows, when you right-click it will bring up the Run as and you can put the user name and password, but with Windows 7, When you Right-Click it just shows "Run as Administrator"

If you need to "Run as different user" then you need to hold the SHIFT button and then Right-Click AX Client.

Learn more about the tip here http://www.winhelponline.com/blog/run-as-different-user-option-inbuilt-windows-7/