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

Notifications

Announcements

No record found.

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 223
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);    }
 
 
 
I have the same question (0)
  • Martin Dráb Profile Picture
    237,965 Most Valuable Professional on at
    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.
  • Verified answer
    Sophs@4Sight Profile Picture
    223 on at
    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);
        }
     

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

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

#1
Martin Dráb Profile Picture

Martin Dráb 503 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 434 Super User 2025 Season 2

#3
BillurSamdancioglu Profile Picture

BillurSamdancioglu 278 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans