Click to Rate and Give Feedback
MSDN
MSDN Library
Microsoft Dynamics
Best Practices
 Clear Code Examples [AX 2012]
Collapse All/Expand All Collapse All
Microsoft Dynamics AX 2012
Clear Code Examples [AX 2012]

Updated: November 30, 2011

Applies To: Microsoft Dynamics AX 2012 Feature Pack, Microsoft Dynamics AX 2012

The code in the two examples below can be rewritten to be much clearer.

From:

if (args.parmEnumType() != enumnum(BMBuildIdEnum))

{

    if (args.record().tableId == tableNum(BMmoduleTable))

    {

        moduleTable = args.record();

        buildId = moduleTable.buildId;

    }

    else

    {

        return null;

    }

}

else

{

    buildId = args.parmEnum();

}

...

To:

if (args.parmEnumType() == enumNum(BMBuildIdEnum))

{

    buildId = args.parmEnum();

}

else

{

    if (args.record().tableId == tableNum(BMmoduleTable))

    {

        moduleTable = args.record();

        buildId = moduleTable.buildId;

    }

    else

    {

        return null;

    }

}

...

The rewrite puts the most important case first, and removes the negative logic used in the first if statement in the first version of the code.

From:

ledgerJournalTrans = this.ledgerJournalTransInitFromCreate(_tmpProjAdjustmentCreate);

    if (ledgerJournalTrans.validateWrite())

    {

        ledgerJournalTrans.insert();

        ProjPostLedger = ProjPost::construct(ledgerJournalTrans,ledgerVoucherTrans);

        if (projPostLedger.checkTrans())

        {

            projPostLedger.PostTrans();

        }

        else

        {

            throw error("@SYS21628");

        }

    }

    else

    {

        throw error("@SYS21628");

    }

    ledgerjournalTrans.delete(false);

...

To:

ledgerJournalTrans = this.ledgerJournalTransInitFromCreate(_tmpProjAdjustmentCreate);

if (!ledgerJournalTrans.validateWrite())

{

    throw error("@SYS21628");

}

ledgerJournalTrans.insert();

ProjPostLedger = ProjPost::construct(ledgerJournalTrans,ledgerVoucherTrans);

     

if (!projPostLedger.checkTrans())

{

    throw error("@SYS21628");

}

    projPostLedger.PostTrans();

    ledgerjournalTrans.delete(false);

...

Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
© 2012 Microsoft. All rights reserved. Terms of Use | Trademarks | Privacy Statement
Page view tracker