Generic table methods

Generic/standard table methods:

    /// <summary>
    /// Find by natural key
    /// </summary>
    /// <param name = "_id">id</param>
    /// <param name = "_forUpdate">for update</param>
    /// <returns>VKTable record</returns>
    static VKTable find(VKIdentifier      _id,
                                  boolean           _forUpdate = false)
    {
        VKTable table;

        if (_id)
        {
            if (_forUpdate)
            {
                table.selectForUpdate(_forUpdate);
            }

            select firstonly table
                where table.Id == _id;
        }

        return interfaceSetup;
    }

    /// <summary>
    /// Find by RecId
    /// </summary>
    /// <param name = "_refRecId">RecId reference</param>
    /// <param name = "_forUpdate">for update</param>
    /// <returns>VKTable record</returns>
    static VKTable findRecId(RefRecId    _refRecId,
                                       boolean              _forUpdate = false)
    {
        VKTable table;

        if (_refRecId)
        {
            if (_forUpdate)
            {
                table.selectForUpdate(_forUpdate);
            }

            select firstonly table
                where table.RecId == _refRecId;
        }

        return interfaceSetup;
    }

    static boolean exist(CustAccount _custAccount)
    {
        return _custAccount && (select firstonly RecId from custTable
                                    where custTable.AccountNum == _custAccount).RecId != 0;
    }

    [SysClientCacheDataMethodAttribute(true)]
    display AmountMST amountChargedNotPosted()
    {
        return 0;
    }

    /// <summary>
    /// Interface id lookup
    /// </summary>
    /// <param name = "_formControl">FormStringControl</param>
    /// <param name = "_interfaceType">VKInterfaceType</param>
    public static void lookupInterfaceId(FormStringControl _formControl, VKInterfaceType _interfaceType = VKInterfaceType::None)
    {
        Query                   query = new Query();
        QueryBuildDataSource    queryBuildDataSource = query.addDataSource(tableNum(VKInterfaceSetup));

        if (_interfaceType)
        {
            QueryBuildRange     qbrInterfaceType = SysQuery::findOrCreateRange(queryBuildDataSource, fieldNum(VKInterfaceSetup, InterfaceType));
            qbrInterfaceType.value(QueryValue(_interfaceType));
        }
        SysTableLookup sysTableLookup = SysTableLookup::newParameters(tableNum(VKInterfaceSetup), _formControl);
     
        sysTableLookup.addLookupField(fieldNum(VKInterfaceSetup, InterfaceId), true);
        sysTableLookup.addLookupField(fieldNum(VKInterfaceSetup, InterfaceDescription));
        sysTableLookup.addLookupField(fieldNum(VKInterfaceSetup, InterfaceDirection));
    
        sysTableLookup.parmQuery(query);
     
        sysTableLookup.performFormLookup();
    }

CoC extension display method:
/// <summary>
/// CoC extension ащк InventTestAssociationTable table
/// </summary>
[ExtensionOf(tableStr(InventTestAssociationTable))]
final class VKInventTestAssociationTable_Extension
{
    /// <summary>
    /// Display method to return InventTestGroup description
    /// </summary>
    /// <returns>InventTestGroup description</returns>
    [SysClientCacheDataMethodAttribute(true)]
    display Description displayInventTestGroupDescription()
    {
        return (select Description from InventTestGroup where InventTestGroup.TestGroupId == this.TestGroupId).Description;
    }

}
This then can be added to the existing table group Data Field equals to: VKInventTestAssociationTable_Extension::displayInventTestGroupDescription.

[SysClientCacheDataMethodAttribute(true)]
When it's cached (attribute above), the display method value is only refreshed when the table record is updated (or not even then, depending on the setup).

Be aware that it is also possible to use method parameter like in the following example.
CoC extension display method on the form data source:
/// <summary>
/// CoC extension for ProdBOM form InventDim data source
/// </summary>
[ExtensionOf(formdatasourcestr(ProdBOM, InventDim))]
final class VKProdBOMFrm_InventDimDS_Extension
{
    /// <summary>
    /// Display method to return disposition code
    /// </summary>
    /// <param name = "_inventDim">InventDim</param>
    /// <returns>PdsDispositionCode</returns>
    display PdsDispositionCode vkPdsDispositionCode(InventDim _inventDim)
    {
        ItemId      itemId = element.ProdBOM.ItemId;
        InventBatch InventBatch;
        if (itemId)
        {
            select RecId, PdsDispositionCode from inventBatch
                where inventBatch.inventBatchId == _inventDim.inventBatchId
                    &&inventBatch.itemId        == itemId;
        }
        else
        {
            select RecId, PdsDispositionCode from inventBatch
                where inventBatch.inventBatchId == _inventDim.inventBatchId;
        }
        return inventBatch.PdsDispositionCode;
    }
}




 

Search

About

DaxOnline.org is free platform that allows you to quickly store and reuse snippets, notes, articles related to Dynamics AX.

Authors are allowed to set their own AdSense units.
Join us.

Blog Tags