Thursday, September 26, 2013

Recycling number sequence

So far I've seen a few instances where standard AX2012 can't handle continuous number sequence on certain EDT. Purchase order number (PurchId) is one of those affected.
- If you create a new order and then delete it, no numbers added to the status list and the purchId is not recycled.
- If you create a new order using the "Create purchase order" form, and click "cancel" in the form. The number is now added to the status list. Then the number can be freed by the clean-up action.

In these cases, one option is to add code to free the number ourselves. Using PurchId as an example, add the code below at purchTableType.delete() method will add the purchId to the status list of the number sequence.

// Add the line below to free up the purchId
NumberSeq::releaseNumber(PurchParameters::numRefPurchId().NumberSequenceId, purchTable.PurchId); 

One thing to consider, though, is that we have to be sure the Id we are freeing are no longer used/referenced in other tables in AX. Other than that, it should be pretty straight forward.

Please leave a comment if you think of other things to consider when making this change. =D


This posting is provided "AS IS" with no warranties, and confers no rights.

Thursday, September 05, 2013

Lookup dimension attributes used in a company.

This job look up the financial dimension attributes which are being used in the current company/entity. I used it while writing certain import customization. You might find other use of it.
static void Job_GetDefaultDimensions(Args _args)
    DimensionEnumeration            dimEnum;
    DimensionAttributeSetItem       dimAttrSetItem;
    DimensionAttribute              dimAttr;
    container   cDimAttr, cDimAttrName;

    // Get the financial dimensions
    dimEnum = DimensionCache::getDimensionAttributeSetForLedger();

    while select * from dimAttr
        order by dimAttr.Name asc
        join dimAttrSetItem
        where dimAttrSetItem.DimensionAttribute == dimAttr.RecId
            && dimAttrSetItem.DimensionAttributeSet == dimEnum
            && dimAttr.Name != "MainAccount"
        cDimAttr = conIns(cDimAttr, conLen(cDimAttr)+1, dimAttr.recId);
        cDimAttrName = conIns(cDimAttrName, conLen(cDimAttrName)+1, dimAttr.Name);
This posting is provided "AS IS" with no warranties, and confers no rights.