Thursday, May 25, 2023

How to add a custom dimension to Financial dimensions in d365

 Here my requirement is to add a custom dimension to financial dimensions.

1.Create a Table



2. Create a View with the above table.

    Note : Name the datasource as BackingEntity
                Name the View fields as Key(Recid), value(EntityCode),Name(EntityName).




3. View Method.

public class DataAttributeDaxEntityTable extends common
{
        /// <summary>
    ///    /// </summary>
    /// <param name="_dimensionEnabledType"></param>
    [SubscribesTo(classStr(DimensionEnabledType), delegateStr(DimensionEnabledType, registerDimensionEnabledTypeIdentifiersDelegate))]
    public static void DimensionEnabledType_registerDimensionEnabledTypeIdentifiersDelegate(DimensionIEnabledType _dimensionEnabledType)
    {
        _dimensionEnabledType.registerViewIdentifier(tableStr(DataAttributeDaxEntityTable));
    }
}

4. General Ledger > Chart of Accounts > Dimension > Financial Dimensions.

    Note : To Activate the custom dimension the system should be in Maintenance mode.
    To Activate the Maintenance mode find the below Sql Query:
    Run the query in SSMS.
        update SQLSYSTEMVARIABLES SET VALUE = 1 where PARM = 'CONFIGURATIONMODE'

Restart the world wide Web publishing services.
After maintenance mode status becomes Active.

5.General Ledger > Chart of Accounts > Structures>Configure account structures

    click on Edit button>Add segement >EntityCode
    To Activate Account structures VM should be back to  normal mode.
        Run the query in SSMS.
        update SQLSYSTEMVARIABLES SET VALUE = 0 where PARM = 'CONFIGURATIONMODE'
Restart the World Wide Web Publishing Service to reset IIS.
    

To verirfy check the financial dimensions tab.


My requirement is to add a custom field in line level with the lookup of our custom table.


If i select the dimension in custom field it should merge the ledger dimension and update.


By modifying the entity code field it should update the account field entitycode dimension.

Code  :

internal final class DaxEntitycode_lookupEventHandler
{
        /// <summary>
    ///    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    [FormControlEventHandler(formControlStr(LedgerJournalTransDaily, LedgerJournalTrans_EntityCode), FormControlEventType::Lookup)]
    public static void LedgerJournalTrans_EntityCode_OnLookup(FormControl sender, FormControlEventArgs e)
    {
        Query query = new Query();
        QueryBuildDataSource queryBuildDataSource;
        QueryBuildRange queryBuildRange;
        SysTableLookup sysTableLookup;
        sysTableLookup = SysTableLookup::newParameters(tableNum(DaxEntityTable),sender,true);
        sysTableLookup.addLookupField(fieldNum(DaxEntityTable,Code  ));
        sysTableLookup.addLookupField(fieldNum(DaxEntityTable, EntityName));
        queryBuildDataSource = query.addDataSource(tableNum(DaxEntityTable));
        sysTableLookup.parmQuery(query);
        sysTableLookup.performFormLookup();
    }
}

.......................................................................................

[ExtensionOf(tableStr(LedgerJournalTrans))]
final class DaxLedgerJournalTrans_Extension
{
    /// <summary>
    /// This method is used to modify the Entitycode field.
    /// </summary>
    /// <param name = "_fieldId">fieldId</param>
    public void modifiedField(fieldId _fieldId)
    {
        DimensionAttributeValueSetStorage   valueSetStorage = new DimensionAttributeValueSetStorage();
        LedgerJournalTrans  ledgerJournalTrans;
        RecId               dimension1,dimension2;
        DimensionAttribute      dimensionAttribute;
        DimensionAttributeValue dimensionAttributeValue;
          next modifiedField(_fieldId);
        switch(_fieldId)
        {
            case fieldnum(LedgerJournalTrans, EntityCode):
              if(this.EntityCode !="" && this.AccountType == LedgerJournalACType::Ledger)
                {
                    dimensionAttribute = dimensionAttribute::findByName("EntityCode");
                    dimensionAttributeValue = dimensionAttributeValue::findByDimensionAttributeAndValue(dimensionAttribute,this.EntityCode ,false,true);
                    valueSetStorage.addItem(dimensionAttributeValue);
                    dimension1  = valueSetStorage.save();
                    dimension2  = LedgerDimensionFacade::getDefaultDimensionFromLedgerDimension(this.LedgerDimension);
                    this.LedgerDimension    = LedgerDimensionFacade::serviceCreateLedgerDimension(LedgerDefaultAccountHelper::getDefaultAccountFromMainAccountRecId( LedgerDimensionFacade::getMainAccountRecIdFromLedgerDimension(this.LedgerDimension)), dimension1,dimension2);
                }
                break;
            default:
        }
    }
}

Reference blog :

https://viwekmsdynamics.wordpress.com/2016/11/28/set-financial-dimensions-by-x-code-in-ax-2012/    












    









No comments:

Post a Comment