Skip to main content

Notifications

Announcements

No record found.

Dynamics 365 Community / Forums / Finance forum / How to code a Data Ent...
Finance forum
Answered

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

Posted on by 92
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
    Sophs@4Sight 92 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
    Martin Dráb 228,493 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

Anton Venter – Community Spotlight

Kudos to our October Community Star of the month!

Announcing Our 2024 Season 2 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Dynamics 365 Community Newsletter - September 2024

Check out the latest community news

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 290,524 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 228,493 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans