Friday, August 21, 2015

Extension Framework and SysGlobalCache issue

There is a new extension framework in AX 2012 that facilitates developing customized class hierarchies by using attributes for instantiating the needed descendant.

I used this simple and brilliant article by Joris de Gruyter while creating all the needed artefacts to test the framework.

Unfortunately, his remark in bold not to forget to Refresh elements after adding a new attribute value for a new descendant class did not help: my test class still instantiated my base TmxDynamics class!






After debugging I found that the Refresh elements does not actually flush StaticMaps for values in GlobalCache.




Neither does SysExtensionCache::clearAllScopes() nor SysFlushAOD::clearGlobalCaches() actually flush the  "SysExtAppClassSearchStratDepth.checkDerivedClasses", which is responsible for finding all inherited classes.

I do not know if this is a Microsoft bug, but if you cannot manage to get your newly added class, try to flush this value from the global cache.


I got what I want.



Happy cache-flushing!

Thursday, April 16, 2015

Make your decision on a new voucher

This is just a short note on new voucher allocation from code.

When you need to allocate a new voucher from a form, use _makeDecisionLater = true, when from code _makeDecisionLater = false; or, alternatively, it should be balanced with a used() call.

Got it from the forum.

A good point to start is the archived article (Russian).

Friday, January 23, 2015

Breakpoint; in CIL code

I needed to debug batch processing in BatchRun.ServerGetTask() method.









It was a wrong idea to add breakpoint; instruction into a managed code. Of course, after stopping my AOS did not start anymore because of the error:

Just-In-Time debugging this exception failed with the following error: The operation attempted is not supported

The easiest way to recover this problem is to delete the forementioned instruction and recompile CIL, but I have not access to AOT X++ editor anymore.

Alternatevily, as described in How-To-Debug-Managed-Code-In-AX2012, I did catch this breakpoint in Visual Studio during the short period between Starting and Stopped statutes of AOS service.

Launch Visual Studio as administrator.



Open the class method in question directly frpm xppCIL\Source folder.





Start the AOS service.



Switch back to Visual Studio and attach to the process. It appeared in a few seconds.



Then it stopped at the problematic breakpoint.



Pressing F5 each time it stopped there (actually every minute, as it supposed to be for batch processing), I changed my code back and run full CIL.



Please, do not place breakpoint; in managed code like I did.

Full MSDN article about debugging in AX 2012.

Tuesday, January 20, 2015

Fast full compilation in AX 2012

This is just a short batch that runs a full compilation by means of AxBuild with after-run cleaning in AX 2012.

c:
cd "C:\Program Files\Microsoft Dynamics AX\60\Server\CGI_DAX62_DEVTM2_AOS1\bin"
axbuild xppcompileall  /s=01 /altbin="C:\Program Files (x86)\Microsoft Dynamics AX\60\Client\Bin"
@echo to start compilation log import press any key
pause
cd "C:\Program Files (x86)\Microsoft Dynamics AX\60\Client\Bin"
ax32.exe -startupCmd=importandcompileaxbuildlog_C:\Program*Files\Microsoft*Dynamics*AX\60\Server\CGI_DAX62_DEVTM2_AOS1\Log
pause

Do not forget to run it as administrator.





The cleaning requires a project installed as described in the second hyper link.





Tuesday, December 30, 2014

Batch task progress on server for AX 2009

I already explained how to update progress for batch tasking in AX 2012. Now, it's time for AX2009.

You can simply change new() method in SysOperationProgressServer class as follows:


public void new(int _numberOfBars = 1, boolean _bypass=false)


Evidently it will increase the total execution time of a batch because SysProgress table will be updated for every task as many times as you call incCount(), setCount() etc.

So, it is worth changing construct method in RunbaseProgress class, so that the developer could decide to update progress or not.


Happy New Year!

Friday, November 21, 2014

How to print labels in multiple languages

This is a short job to print labels in English US and English Canada. The prefix defines the label file.

static void printLabels(Args _args)
{
    int     labelNum = 1;
    int     labelIndex;
    int     labelMaxNum = 216;
    str     labelPrefix = "@CGI";
    str     labelStr;
    str     languageIdEN = 'en-us';
    str     languageIdFR = 'en-ca';

    for (labelIndex = labelNum; labelIndex <= labelMaxNum; labelIndex++)
    {
        labelStr = labelPrefix + int2str(labelIndex);
        labelStr = strFmt("%1 : %2 /// %3", labelStr,
                                            SysLabel::labelId2String2(strFmt("%1", labelStr), languageIdEN),
                                            SysLabel::labelId2String2(strFmt("%1", labelStr), languageIdFR));
        info( labelStr);
    }
}

Tuesday, November 11, 2014

How to convert a wrong date

Standard str2date function tries to fix a wrong date. For example, if we got as a parameter fantastic June 31th, it returns us June 30, which can be a bad result for your business case.



There are at least two possible solutions for that.

First, by converting the result back to a string and comparing it with the initial string.

private container cgiValidateDate(str _dateStr)
{
    date                retDate     = str2Date(_dateStr, #cgiDateFormat);
    boolean             isOK        = true;
    str                 madeDateStr = date2StrUsr(retDate, DateFlags::FormatAll);

    if(retDate == dateNull() || _dateStr != madeDateStr)
    {
        error(strFmt("Date %1 is incorrect", _dateStr));
        isOK = false;
    }

    return [isOK, retDate];
}


Second, by using .Net function tryParse.


private container cgiValidateDate(str _dateStr)
{
    date                retDate;
    utcDateTime         retDateTime;
    boolean             isOK        = true;
    
    if(!System.DateTime::TryParse(_dateStr, byref retDateTime))
    {
        error(strFmt("Date %1 is incorrect", _dateStr));
        isOK = false;
    }
    else
    {
        retDate = DateTimeUtil::date(retDateTime);
    }
    return [isOK, retDate];
}


Happy date converting!