Skip to main content

Notifications

Community site session details

Community site session details

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

How to code a Data Entity to Import table with User and DimensionAttributeValue's RecId

(1) ShareShare
ReportReport
Posted on by 169
Hi
I have created a custom table consisting only of a USERID and DIMENSIONVALUE. (RecId of the DimensionAttributeValue.RecId).
What is the correct way to create a DataEntity to be able to import records into this table but allowing the user to indicate the DisplayValue and not the recid of the DimensionValue. I have created a dataEntity and also added code to defaultrow() and persistEntity but the DimensionValue is always 0 when it is imported. 
public void defaultRow()    {        super();        if (!this.DimensionValue)        {            this.DimensionValue = DimensionAttributeValue::findByDimensionAttributeAndValue(DimensionAttribute::find(ACCRecSecParameters::find().DimensionAttributeRecId),this.DisplayValue,false,false).RecId;        }    }     ///<summary>     ///</summary>     ///<param name = /_entityCtx/></param>    public void persistEntity(DataEntityRuntimeContext _entityCtx)    {        this.skipDataSourceValidateField(fieldNum(ACCRecSecUserMappingEntity, DimensionValue), true);        if (_entityCtx.getDatabaseOperation() == DataEntityDatabaseOperation::Insert)        {            this.DimensionValue = DimensionAttributeValue::findByDimensionAttributeAndValue(DimensionAttribute::find(ACCRecSecParameters::find().DimensionAttributeRecId),this.DisplayValue,false,false).RecId;        }        super(_entityCtx);    }
 
 
 
  • Verified answer
    Sophs@4Sight Profile Picture
    169 on at
    How to code a Data Entity to Import table with User and DimensionAttributeValue's RecId
    Thank You Martin for your response
    I was able to solve the problem by using the following code and populating the buffer for the DimensionAttributeValue.
    public void initializeEntityDataSource(DataEntityRuntimeContext _entityCtx, DataEntityDataSourceRuntimeContext _dataSourceCtx)
        {
            if (_dataSourceCtx.name() == dataEntityDataSourceStr(ACCRecSecUserMappingEntity, DimensionAttributeValue))
            {
                DimensionAttributeValue    bufDimensionAttributeValue =   DimensionAttributeValue::findByDimensionAttributeAndValue(DimensionAttribute::find(ACCRecSecParameters::find().DimensionAttributeRecId),this.DisplayValue,false,false);
    
                _dataSourceCtx.setBuffer(bufDimensionAttributeValue);
            }
            super(_entityCtx, _dataSourceCtx);
        }
     
  • Martin Dráb Profile Picture
    233,733 Most Valuable Professional on at
    How to code a Data Entity to Import table with User and DimensionAttributeValue's RecId
    Having DimensionAttributeValue joined to your table (under Data Sources) is the correct approach (if you want to use the entity for export too or avoid code in import); make also sure that DimensionAttributeValue has Is Read Only set to Yes.
     
    You seem want to always import data for a single dimension attribute (defined in ACCRecSecParameters.DimensionAttributeRecId). If you want to avoid code, you can join it to DimensionAttributeValue in your entity definition.
    ​
    If you want to write code, I would place it to mapEntityToDataSource().
     
    Also, use the debugger to understand what's going in your code. As you see, just knowing that it doesn't produce the right result isn't sufficient information.

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

Announcing the Engage with the Community forum!

This forum is your space to connect, share, and grow!

🌸 Community Spring Festival 2025 Challenge Winners! 🌸

Congratulations to all our community participants!

Adis Hodzic – Community Spotlight

We are honored to recognize Adis Hodzic as our May 2025 Community…

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

#1
Martin Dráb Profile Picture

Martin Dráb 510 Most Valuable Professional

#2
Saalim Ansari Profile Picture

Saalim Ansari 315

#3
Adis Profile Picture

Adis 312 Super User 2025 Season 1

Overall leaderboard

Product updates

Dynamics 365 release plans