Skip to main content

Notifications

Announcements

No record found.

Finance | Project Operations, Human Resources, ...
Suggested answer

Entity questions

(1) ShareShare
ReportReport
Posted on by 1,293
Hi, 

1. if we want to add a field to the entity, do we need to add it to the staging table in order to be able to import/export successfully? or does it work without adding the field to staging table?
 
2. If we want to add a field to the entity, but I don't want the user to be able to import or export it's value. Is the only way to make the field private? or i can do that by not adding the field to the staging table? (depends on the answer for #one)
 
3. The reason for question 2, is because i want to add a field to the entity but only set it by code in case of import, i don't want the user to provide it's value. Also when exporting, it will be good to not see the field value as well.
Categories:
  • Martin Dráb Profile Picture
    Martin Dráb 230,569 Most Valuable Professional on at
    Entity questions
    Please don't start again the discussion about setting SalesLine.Table1RecId in code. The topic of this thread is different and you already have a thread for that (add recId field to entity).
  • Martin Dráb Profile Picture
    Martin Dráb 230,569 Most Valuable Professional on at
    Entity questions
    You already have code in your other thread setting a table field (in mapEntityToDataSource()), which is the answer to your question "if i'm not going to expose the field as an entity field, then how am i going to import it's value by code?".
  • .. Profile Picture
    .. 1,293 on at
    Entity questions
    Hi Andre,

    3. The relation between SalesLine and Table1 is SalesLine.Table1RecId == Table1.RecId

    The Number field in Table1 is unique and yes the number can be repeated on multiple order lines
     
    I didn't add the number field in the entity extension. I only added SalesLine.Table1RecId as a private field
    And when importing the file, i want SalesLine.Table1RecId to be set by code based on other imported field values in the file (salesLine.Id, salesLine.ItemId, Table1.CodeX) as the code i showed in the previous reply
  • André Arnaud de Calavon Profile Picture
    André Arnaud de Cal... 291,885 Super User 2024 Season 2 on at
    Entity questions
    Hi,

    After reading the question, replies, and comments hereby my thoughts.
     
    1. You will need the staging table updated for data management purposes. Import won't work without the staging table updated. You got the point from Martin. The staging table stores records and maintains the import status. As mentioned by Mohamed, you can use an automation to update the staging table. About OData, this is this a view where you directly interact with the data (read or write). Then indeed, the staging table is not used.
     
    3. Is the relation one on one for these tables or can a number occur on multiple order lines? Is the Number field part of the data entity extension? 
  • .. Profile Picture
    .. 1,293 on at
    Entity questions
    Hi Martin,

    1. So we can't export or import a certain field via DMF, if the field doesn't exist in staging table?
    For odata, i don't think we need staging table for it to work, do we?

    for 2+3, if i'm not going to expose the field as an entity field, then how am i going to import it's value by code?
    please look at my previous reply for Mohammed in point 3
  • .. Profile Picture
    .. 1,293 on at
    Entity questions
    Hi Mohammed,

    For question 1, my questions wasn't about ordering. My question was, if I don't add the field to staging table and just to the entity, would the export or import fail? or i can still see the field value when exporting and I can still import it even if it doesn't exist in the staging table
     
    For question 2, is there any other way other than making it private or deleting it?

    For question 3: I don't think unmapped field will work, or please guide me if it will work in my case

    I created the custom table "Table1"  (this table "unique index" is field "Number")
    Number    Id       codeX      codeY      Field1
    ------        ---      -------      -------     --------
    1               id1     codex1     codey1      fieldz
    2               id2     codex1     codey1      fieldz

    So i added "Table1" to salesOrderLineV2Entity, i added it as readOnly datasource and with outerjoin to SalesLine

    The relationship between Table1 and SalesLine is RecId:
    SalesLine.Table1RecId == Table1.RecId
     
    I added SalesLine.Table1RecId as a private field to the entity. I also added codeX field from Table1 to the entity

    Now i want to set SalesLine.Table1RecId by code based on the imported field value of CodeX
    but i'm getting this error:
    Field Table1RecId is private and can only be referenced from within the element in which it is declared
    [ExtensionOf(tableStr(SalesOrderLineV2Entity))]
    final class SalesOrderLineV2Entity_Extension
    {
        public void mapEntityToDataSource(DataEntityRuntimeContext _entityCtx, DataEntityDataSourceRuntimeContext _dataSourceCtx)
        {
    
            next mapEntityToDataSource(_entityCtx, _dataSourceCtx);
    
            switch (_dataSourceCtx.name())
            {
                case dataEntityDataSourceStr(SalesOrderLineV2Entity, SalesLine):
                    //SalesLine salesLine = _dataSourceCtx.getBuffer() as SalesLine;
                    break;
                case dataEntityDataSourceStr(SalesOrderLineV2Entity, Table1):
                    //Table1 table1 = _dataSourceCtx.getBuffer() as Table1;
    
                    Table1 table1Local;
                    select firstonly table1Local where table1Local.Id == this.Id
                        && table1Local.CodeY == this.ItemNumber
                        && table1Local.CodeX == this.CodeX
                        && table1Local.IsActive == true;
    
                    this.Table1RecId = table1Local.RecId;
                    break;
    
            }
        }
    
    }
     
     
  • Suggested answer
    Martin Dráb Profile Picture
    Martin Dráb 230,569 Most Valuable Professional on at
    Entity questions
    1. If the data entity supports data management and you want to use it, you need to add the field to the staging table. Note that this isn't the only way how to use data entities - there are also OData services (and a plenty of features based on them).
    2.+3. Another option is not exposing the table field as an entity field at all.
    Mohamed's suggestion to use an ummapped field doesn't make sense to me. You'd use it if you want to import and export a value that isn't directly mapped to a table field, but your scenario is the opposite. You have a table field that you don't want to export and import.
  • Suggested answer
    Mohamed Amine Mahmoudi Profile Picture
    Mohamed Amine Mahmoudi 11,704 Super User 2024 Season 2 on at
    Entity questions
    Hi @..,
     
    1. there's no problem with the order, but you must have the same name, otherwise you can use "Update stagig table" or "Regenrate staging table" in the entity. 
     
    2. Yes you can use private or allow edit if want otherwise you can delete it.
    3. you can use Unmapped field.
     
    Best regards,
    Mohamed Amine MAHMOUDI

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

Congratulations 2024 Spotlight Honorees

Kudos to all of our 2024 community stars! 🎉

Meet the Top 10 leaders for December

Congratulations to our December super stars! 🥳

Start Your Super User Journey Pt 2

Join the ranks of our community heros! 🦹

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,885 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,569 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans