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 80
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 80 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 224,910 Super User 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.

Helpful resources

Quick Links

Can you answer this forum question?

You could make someone's day!

Community Newsletter - May 2024

Kudos to our community stars!

Community Spotlight of the Month

Kudos to Mohamed Amine Mahmoudi!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 283,676 Super User

#2
Martin Dráb Profile Picture

Martin Dráb 224,910 Super User

#3
nmaenpaa Profile Picture

nmaenpaa 101,146

Featured topics

Product updates

Dynamics 365 release plans