sábado, 22 de septiembre de 2012

When buf2buf is not enough

When the global buf2buf is not enough! Copying two heterogeneous table buffers, but with practically the same field names.
Edit: Peter Chan beat me to it! The only advantage to using my function is an extra semi colon :)
Neither of our methods check to see if the field type is the same...
///Copy two different table buffers but with the same field names.
///May be better to use a Map...
static void bufFields2BufFields(
    Common  _from,
    Common  _to
    )
{
    DictTable   dictTableFr = new DictTable(_from.TableId);
    FieldId     fieldIdFr;
    DictTable   dictTableTo = new DictTable(_to.TableId);
    FieldId     fieldIdTo;
    FieldName   fieldName;
    ;
    fieldIdFr   = dictTableFr.fieldNext(0);
    fieldName   = dictTableFr.fieldName(fieldIdFr);
    fieldIdTo   = dictTableTo.fieldName2Id(fieldName);

    while (fieldIdFr && ! isSysId(fieldIdFr))
    {
        if (fieldIdTo)
        {
            _to.(fieldIdTo)     = _from.(fieldIdFr);
        }
        
        fieldIdFr           = dictTableFr.fieldNext(fieldIdFr);
        fieldName           = dictTableFr.fieldName(fieldIdFr);
        fieldIdTo           = dictTableTo.fieldName2Id(fieldName);
    }
}

miércoles, 5 de septiembre de 2012

AX 2012 Number Sequence, X++

It's feels like having to learn all of this stuff over again.  Here is a brief overview, and there is a white paper available as well, for AX 2012.

static void tutorial_NumberSequenceJob(Args _args)
{
    // AX 2012 Number Sequence, X++
    // Only for sequences marked as continuous
    // ---------------------------------------
    NumberSequenceReference nsRef;    
    NumberSeqScope    scope;
    ProductReceiptId  receipt;
    
    scope      = NumberSeqScopeFactory::createDataAreaScope(curext());
    nsRef      = NumberSeqReference::findReference(extendedTypeNum(VendAccount), scope);
    if (nsRef)
    {
        receipt         = NumberSeq::newGetNum( nsRef ).num();
    }
    
    info(strFmt("New Supplier Id is '%1'", receipt));
}