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, ...
Suggested Answer

Handle entity virtual fields in x++

(3) ShareShare
ReportReport
Posted on by 10
Hi,

If we have a table with a container field (that gets filled from the UI like this)
 
 
Now in the entity, i will need to be able to export and import those values

so let's say currently we have 2 values in the available list and one value in the selected list

in the entity i created 3 No/Yes fields (Is Computed Field : No)
Field1
Field2
Field3
 
when exporting for this certain record, i should see the Field1 and Field2 are both no. And field3 is Yes

and when importing i could make Field3 as No and Field2 as yes for example. And this should be reflected in the container field and they should appear correctly in the UI

What code to put in the entity to achieve this?
 
Categories:
I have the same question (0)
  • Martin Dráb Profile Picture
    237,965 Most Valuable Professional on at
    Are you sure you want to violate the first normal form of database design? The recommended design is storing the values in an table with 1:n relation, not in s single field, converted to binary data. Then you can do things like searching the data, index them, export them with data entities and so on.
     
    And if you insist on your design despite all the problem, do you also insist on a solution that can't deal with more than three values?
  • CU22120935-0 Profile Picture
    10 on at
    Hi @Martin Dráb,

    The container field in this table and the table itself is not in my model. So I need to stick with that.
    Quick question (even though i won't implement): if i use a table instead, i will still be able to use the same UI to move things from left to right?

    And yes for now I need three No/Yes fields, and each time they add something new, we will need to add another NoYes field. But it's been a while since they added anything. So hopefully no future changes. Is there another way?

    So now how can i handle the export and import in this case please and as I described in the question using the three fields and using another way if you have one?
  • Suggested answer
    Martin Dráb Profile Picture
    237,965 Most Valuable Professional on at
    Sure, the UI can be the same even with the correct data model. These are two separate things. You can find plenty of examples in the standard application where it's done this way.
     
    Your question seems to be how to work with your container in code, such as getting and setting a value at a particular index. Check out X++ container runtime functions in F&O documentation. You'll learn that you can use conPeek() to get a value and conPoke() to set a value. You can also use a special syntax involving [ ], but let's keep it simple here.
     
    Implementing your virtual fields will be trivial - you simply call conPeek() three times (with varying indexes) and assign a value to your three fields.
     
    On import, you'll create a container from your three virtual fields and assign the container to the table field.
     
    An alternative design would be having a single virtual field with containing all the values separated by a delimiter. An advantage is that it wouldn't require development when the number of values change. You can see this approach when importing and exporting financial dimensions.
  • CU22120935-0 Profile Picture
    10 on at
     
    I was also thinking that I should use conPeek in case of export. But the question is where? is it in postLoad method or mapDataSourceToEntity Method? but mapDataSourceToEntity doesn't get called in export when debugging

    Same thing for import, you said i should use conPoke(), but where? postLoad (but this one gets called in both import and export) or mapEntityToDataSource or inserEntityDataSource or updateEntityDataSource? where to write the code?

    You also said that i can find plenty of examples that use the same UI, can you please tell me how? i click find references on class SysListPanel but didn't find something useful. Most forms don't have datasource or tmp table. What place shall i look at where i can find a table with container field?

    Also if I understood correctly, do you mean financial dimension table has a container field, and when using the entity, we can import the values by a delimiter using one virtual field. Can you please give me the entity name so that I see how it works exactly please?

    @Martin Dráb

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 451 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

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

#3
BillurSamdancioglu Profile Picture

BillurSamdancioglu 239 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans