sábado, 25 de junio de 2011

How to update with queryRun? - Version II

While trying to update a field in a QueryRun object I was receiving an error:
...No olvide TTSBEGIN/TTSCOMMIT y la cláusula FORUPDATE.

So, how do you update with queryRun? This link solved my issue, however there was a niggling feeling that it wasn't the optimum solution available. Here's an alternative suggestion:

/// Deselect (deactivate) all budget forecasts asociated with the project,
///   as it has just been cancelled.
public void EVE_wfCancelOperationDeactivateBFs(ProjId _projId)
{
    Query                   query;
    QueryRun                queryRun;
    QueryBuildDataSource    qbds;
    ProjForecastCost        pfcTable;
    ;

    query = new Query();
    qbds = query.addDataSource(tableNum(ProjForecastCost));
    qbds.update(true);
    qbds.addRange(fieldNum(ProjForecastCost, ProjId)).value(QueryValue(_projId));
    queryRun = new QueryRun(query);

    while ( queryRun.next() )
    {
        pfcTable        = queryRun.get(tableNum(ProjForecastCost));
        ttsBegin;
        //pfcTable.selectForUpdate(true);
        pfcTable.Active = NoYes::No;
        pfcTable.update();
        ttsCommit;
    }
}
Instead of calling the selectForUpdate(true) on the table buffer each time in the loop, we have it applied on the datasource qbds.update(true), which to me is more satisfactory.

jueves, 23 de junio de 2011

The fifth dimension

Working with dimensions can be a little head scratching at times, but being told to place business logic around them can be a wee bit more frustrating. I needed to deactivate an element of the dimension array - a control on a form. I started off with what I knew, which was of course very wrong, and placed the below in the init method of the form:
    projTable_ds.object(fieldnum(ProjTable, Dimension[5])).enabled(false);
There are two things that spit in my face above. The first is that it doesn't compile. The second is that the fifth dimension is indicated explicitly as a number, the code below will explain better:
    int         dimProject;
    ;
    dimProject  = Dimensions::code2ArrayIdx(SysDimension::Proyecto);
So now we can get the index of our 'Project' dimension. The code is more maintainable than just using the integer index directly.
Finally the end result:
    FieldId     dimFieldId, extFieldId;
    DictField   dictField;
    int         dimProject;
    ;

    dimProject  = Dimensions::code2ArrayIdx(SysDimension::Proyecto);
    
    dimFieldId  = fieldnum(ProjTable, Dimension);
    extFieldId  = fieldId2Ext(dimFieldId, dimProject);
    projTable_ds.object(extFieldId).enabled(false);
So the Global::fieldId2Ext() method is what was missing which returns an extended FieldId - a fieldId that includes the the array index.

Heads up to Palle Agermark on this one.

lunes, 20 de junio de 2011

Yet another blog, but there isn't enough information about Axapta.

Time and time again I find myself stumbling over the same blogs to answer my questions about AX 2009. They're actually very good, but the StackOverflow.com web site is probably my favourite place to go for my own questions, although the Microsoft Dynamics Community is an excellent resource as well... Oh and then there is this Columbian guy in the company who is the oracle of all Axapta knowledge but we shouldn't abuse him now should we?

The code in the blog is formatted with FormatMySourceCode so at least it's legible.

Axapta itself is a product that I like very much for both it's usablility - many of our clients are already familiar with MSAccess, and it's development environment. There are warts but they are relatively minor.