web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Unanswered

Default value in CostCenter field in Transfer To Financial Dimension in form AssetTransfer

(0) ShareShare
ReportReport
Posted on by 194
Hello Experts,
I need to show a Defaulted value in CostCenter Lookup field in Transfer To Financial Dimension Section in form Asset Transfer.
I have tried to get it done but it does not work.

I have written code on oninitialize of Assetbook Table using class , it did not work below:
internal final class OnInitializedAssetBookHex
{
    /// <summary>
    ///
    /// </summary>
    /// <param name=/sender/></param>
    /// <param name=/e/></param>
    [FormDataSourceEventHandler(formDataSourceStr(AssetTransfer, AssetBook), FormDataSourceEventType::InitValue)]
    public static void AssetBook_OnInitValue(FormDataSource sender, FormDataSourceEventArgs e)
    {
       /* FormRun formRun = sender.formRun();
        FormStringControl alternateItemGroup = formRun.design().controlName(formControlStr(AssetTransfer, DimensionEntryControlHeader));
        alternateItemGroup.text('Fashion');
        formRun.design().controlName(formControlStr(AssetTransfer, DimensionEntryControlHeader)).allowEdit(false);*/
    }
    /// <summary>
    ///
    /// </summary>
    /// <param name=/sender/></param>
    /// <param name=/e/></param>
    [FormDataSourceEventHandler(formDataSourceStr(AssetTransfer, AssetTmpAssetTransferHistory), FormDataSourceEventType::Initialized)]
    public static void AssetTmpAssetTransferHistory_OnInitialized(FormDataSource sender, FormDataSourceEventArgs e)
    {
        /*FormRun formRun = sender.formRun();
        FormStringControl alternateItemGroup = formRun.design().controlName(formControlStr(AssetTransfer, DimensionEntryControlHeader));
        //alternateItemGroup.text('test');
        formRun.design().controlName(formControlStr(AssetTransfer, DimensionEntryControlHeader)).allowEdit(false);*/
    }
    /// <summary>
    ///
    /// </summary>
    /// <param name=/sender/></param>
    /// <param name=/e/></param>
    [FormDataSourceEventHandler(formDataSourceStr(AssetTransfer, AssetBook), FormDataSourceEventType::Initialized)]
    public static void AssetBook_OnInitialized(FormDataSource sender, FormDataSourceEventArgs e)
    {
        FormRun formRun = sender.formRun();
        DimensionEntryControl alternateItemGroup = formRun.design().controlName(formControlStr(AssetTransfer, DimensionEntryControlHeader));
        //FormStringControl alternateItemGroup = formRun.design().controlName(formControlStr(AssetTransfer, DimensionEntryControlHeader));
        //alternateItemGroup.setDimensionAttributeValue('test');
       // alternateItemGroup.setDimensionAttributeValue(DimensionAttribute::findByName(/CostCenter/),'125');
        DimensionAttribute dimensionAttribute = DimensionAttribute::findByName(/CostCenter/);
      
       // DimensionAttributeValueSet dimensionAttributeValueSet = DimensionAttributeValueSet.RecId where DimensionAttributeValueSet.
       // DimensionAttribute dimensionAttribute = DimensionAttribute::findByLocalizedName
        alternateItemGroup.setDimensionAttributeValue(dimensionAttribute,'100');
      
    //    alternateItemGroup.displayControl();
       // alternateItemGroup.parmDisplayValues(true);
        //alternateItemGroup.saveAttributeValueSet();
        formRun.design().controlName(formControlStr(AssetTransfer, DimensionEntryControlHeader)).allowEdit(false);
    }
}
============
I have also tried writting on INIT of form AssetTransfer using for extension still did not work as below:
public void init()
    {
             
       
      // FormRun formRun;
        FormControl control;
        DimensionDefault                defaultDimension;
      //  DimensionAttributeValueSetItem  dimAttrValueSetItem;
        DimensionAttributeValue         dimAttrValue;
       // DimensionAttribute              dimAttr = DimensionAttribute::findByName(#DimensionName);
        str                             dimensionValue,assetId,dimValue,valueToAssign;
        Random                          random = new Random();
        FormStringControl               assetTmpAssetTransferHistory_DimensionValue,assetTable_AssetId;
        HEX_FATransferIntegrationLog    hex_FATransferIntegrationLog;
        
        next init();
        MultiSelectionContext multiSelectionContext = this.args().multiSelectionContext();
        AssetTable localAssetTable = multiSelectionContext.getFirst() as AssetTable;
        boolean isEditable;
        
        select firstonly hex_FATransferIntegrationLog
            where hex_FATransferIntegrationLog.AssetId == localAssetTable.AssetId;
        if(!hex_FATransferIntegrationLog)
        {
            this.design().controlName(formControlStr(AssetTransfer, CommandOk)).visible(false);
           // this.design().controlName(formControlStr(AssetTransfer, SendForApproval)).labelText(
          
        }
        if(hex_FATransferIntegrationLog && hex_FATransferIntegrationLog.Approved == NoYes::No)
        {
            this.design().controlName(formControlStr(AssetTransfer, CommandOk)).visible(false);
            SendForApproval.text(/Pending for approval/);
          //  dimAttrValueSetItem.DisplayValue = hex_FATransferIntegrationLog.ToAsset;
           // form.design(0).controlName(/DimensionEntryControlHeader/) = hex_FATransferIntegrationLog.ToAsset;
        }
        else if(hex_FATransferIntegrationLog && hex_FATransferIntegrationLog.Approved == NoYes::Yes)
        {
            this.design().controlName(formControlStr(AssetTransfer, CommandOk)).visible(true);
            this.design().controlName(formControlStr(AssetTransfer, SendForApproval)).visible(false);
          //VT
            FormRun formRun = this.args().caller();
            DimensionEntryControl dimensionEntryControl = formRun.design().controlName(/DimensionEntryControlHeader/);
            str dimensionName = /Costcenter/;
            str costCenterValue = /YourCostCenterValue/; // Replace this with the actual value you want to assign
            // Find the CostCenter dimension attribute
            DimensionAttribute dimensionAttribute = DimensionAttribute::findByName(dimensionName);
            if (dimensionAttribute)
            {
                // Find the DimensionAttributeValue corresponding to the given CostCenter value
                DimensionAttributeValue dimensionAttributeValue;
                select firstonly dimensionAttributeValue
        where dimensionAttributeValue.DisplayValue == costCenterValue
        && dimensionAttributeValue.DimensionAttribute == dimensionAttribute.RecId;
                if (dimensionAttributeValue)
                {
                    // Create a new DimensionAttributeValueSetStorage instance
                    DimensionAttributeValueSetStorage dimensionStorage;
                    // Add the DimensionAttributeValue to the DimensionAttributeValueSetStorage
                    dimensionStorage.addItem(dimensionAttributeValue.RecId);
                    // Save the DimensionAttributeValueSetStorage to the DimensionEntryControl
                    dimensionEntryControl.saveAttributeValueSet(dimensionStorage);
                }
                else
                {
                    // If the CostCenter value doesn't exist, handle the case accordingly.
                    // For example, you might create the dimension value or show an error message.
                    error(/CostCenter value not found!/);
                }
            }
            else
            {
                error(/CostCenter dimension attribute not found!/);
            }

           // VT
                    
           
        }
       
    }

Please help me write the correct code and at correct palce to set a prefixed default value in that field. 
I have also Attached the screenshot of where i need that value for better reference.
 
////

Thanks
 
Varun
I have the same question (0)
  • Martin Dráb Profile Picture
    239,118 Most Valuable Professional on at
    Please explain your problem to us. "It does not work" may mean anything.
     
    Also, if you prepare test code focusing just on the single problem, it'll be easier to debug for you and easier to share with others if needed.
     
    (Moved from AX forum to the Finance forum.)
  • Mitr Profile Picture
    194 on at
    Hello Martin,
    Thank you for your response. I am new to Finance and operation developmemnt so sorry for not putting the problem correctly.
    I will try here to put the problem corrrectly.
    I need to show a Default value in CostCenter Lookup field in "Transfer To Financial Dimension" Section in form Asset Transfer.
     
    Lets say I open the Fixed Asset Page for Fixed Asset A00006 and click on action "Transfer fixed Asset".
    AssetTransfer form is opened.
    We have one more custom table "TransferFixedAssetLog" it has fields "AssetID" and "TransferToDimension".
    So on open of form AssetTraansfer page my logic should check if the custom table TransferFixedAssetLog has a record for Asset A00006 with a dmension value in field  "TransferToDimension".
    If found record the AssetTransfer form will show the TransferToDimension value in custcenter field in "Transfer To Financial Dimension" Section.
    Image in red below:
     
    I need to know whaat code to write and hwere to write. I used my small brain an wrote code but not to avail. So need your help or hint to get it done.

    Thanks 
    Varun Tripathi

     
  • Martin Dráb Profile Picture
    239,118 Most Valuable Professional on at
    So which part of your code doesn't work as expected? We should focus on the problem, not on code that actually works fine.
  • Mitr Profile Picture
    194 on at
    Hello Martin,
    I have written code on INIT of form AssetTransfer using for extension still did not work as below in bold and the last that shoudl impact and show default costcenter in red color:
    public void init()
        {
                 
           
          // FormRun formRun;
            FormControl control;
            DimensionDefault                defaultDimension;
          //  DimensionAttributeValueSetItem  dimAttrValueSetItem;
            DimensionAttributeValue         dimAttrValue;
           // DimensionAttribute              dimAttr = DimensionAttribute::findByName(#DimensionName);
            str                             dimensionValue,assetId,dimValue,valueToAssign;
            Random                          random = new Random();
            FormStringControl               assetTmpAssetTransferHistory_DimensionValue,assetTable_AssetId;
            HEX_FATransferIntegrationLog    hex_FATransferIntegrationLog;
            
            next init();
            MultiSelectionContext multiSelectionContext = this.args().multiSelectionContext();
            AssetTable localAssetTable = multiSelectionContext.getFirst() as AssetTable;
            boolean isEditable;
            
            select firstonly hex_FATransferIntegrationLog
                where hex_FATransferIntegrationLog.AssetId == localAssetTable.AssetId;
            if(!hex_FATransferIntegrationLog)
            {
                this.design().controlName(formControlStr(AssetTransfer, CommandOk)).visible(false);
               // this.design().controlName(formControlStr(AssetTransfer, SendForApproval)).labelText(
              
            }
            if(hex_FATransferIntegrationLog && hex_FATransferIntegrationLog.Approved == NoYes::No)
            {
                this.design().controlName(formControlStr(AssetTransfer, CommandOk)).visible(false);
                SendForApproval.text(/Pending for approval/);
              //  dimAttrValueSetItem.DisplayValue = hex_FATransferIntegrationLog.ToAsset;
               // form.design(0).controlName(/DimensionEntryControlHeader/) = hex_FATransferIntegrationLog.ToAsset;
            }
            else if(hex_FATransferIntegrationLog && hex_FATransferIntegrationLog.Approved == NoYes::Yes)
            {
                this.design().controlName(formControlStr(AssetTransfer, CommandOk)).visible(true);
                this.design().controlName(formControlStr(AssetTransfer, SendForApproval)).visible(false);
              //VT
                FormRun formRun = this.args().caller();
                DimensionEntryControl dimensionEntryControl = formRun.design().controlName(/DimensionEntryControlHeader/);
                str dimensionName = /Costcenter/;
                str costCenterValue = /YourCostCenterValue/; // Replace this with the actual value you want to assign
                // Find the CostCenter dimension attribute
                DimensionAttribute dimensionAttribute = DimensionAttribute::findByName(dimensionName);
                if (dimensionAttribute)
                {
                    // Find the DimensionAttributeValue corresponding to the given CostCenter value
                    DimensionAttributeValue dimensionAttributeValue;
                    select firstonly dimensionAttributeValue
            where dimensionAttributeValue.DisplayValue == costCenterValue
            && dimensionAttributeValue.DimensionAttribute == dimensionAttribute.RecId;
                    if (dimensionAttributeValue)
                    {

                        // Create a new DimensionAttributeValueSetStorage instance
                        DimensionAttributeValueSetStorage dimensionStorage;
                        // Add the DimensionAttributeValue to the DimensionAttributeValueSetStorage
                        dimensionStorage.addItem(dimensionAttributeValue.RecId);
                        // Save the DimensionAttributeValueSetStorage to the DimensionEntryControl
                        dimensionEntryControl.saveAttributeValueSet(dimensionStorage);

                    }
                    else
                    {
                        // If the CostCenter value doesn't exist, handle the case accordingly.
                        // For example, you might create the dimension value or show an error message.
                        error(/CostCenter value not found!/);
                    }
                }
                else
                {
                    error(/CostCenter dimension attribute not found!/);
                }

               // VT
                        
               
            }
           
        }

    can please guide what is wrong with my code.
     
    Thanks
     
    Varun
     

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the March Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Giorgio Bonacorsi Profile Picture

Giorgio Bonacorsi 733

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 461 Super User 2026 Season 1

#3
Syed Haris Shah Profile Picture

Syed Haris Shah 278 Super User 2026 Season 1

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans