How to add value to a new field added to extension entity via export data management

Hello All,

I am trying to add a value to the extended entity after export from data management. Here is what I tried till now:

pastedimage1494262987286v1.png

I added a string Unmapped field to SalesOrderHeaderEntity.Extension called as Testing

I created a class called as Testing class and added the following code:

public static class SalesOrderHeaderEntity_Extension

{

///

///

///

///

[PreHandlerFor(tableStr(SalesOrderHeaderEntity), tableMethodStr(SalesOrderHeaderEntity, initValue))]

public static void SalesOrderHeaderEntity_Pre_initValue(XppPrePostArgs args)

{

SalesOrderHeaderEntity sh;

SalesTable st;

select CustAccount from st where st.SalesId == ‘000772’ && st.DATAAREAID == ‘usmf’;

sh.Testing= “Pre test” + st.CustAccount;

}

}

I also tried the same with other methods such as insertEntityDataSource, mapEntityToDataSource (pre-event handler or Post-event handler)

When I export the data via data management

and the testing field is still blank

What am I doing wrong? Kindly advice

Thanks in advance

Shankar Iyer

What are you trying to achieve by that?
Where do you expect to see the value if the field isn’t mapped to anything?

Hello Martin,

What are you trying to achieve by that? Where do you expect to see the value if the field isn’t mapped to anything

We are trying to pull data from D365/Ax to EXCEL. Basically we are trying to add a new field in the extension entity.

In the class we are assigning that field a value and what we need to see in the end is when we export to excel, that newly created must have that value which we assigned it.

Please let me know if you need more details

Thanks in advance,

Shankar Iyer :slight_smile:

If you want to add a regular field, simply add it to a table extension and then drag it from datasource fields to entity fields in your entity extension.

If you want a calculated field, either use computed columns or a virtual fields.

It seems that you tried to implement a read-only virtual field, but you’re not doing it right. initValue() is a completely wrong method for this purpose, you need postLoad().

Hi Martin,

If you want to add a regular field, simply add it to a table extension and then drag it from datasource fields to entity fields in your entity extension. If you want a calculated field, either use computed columns or a virtual fields

Works for out of the box fields. What I am trying to do is adding a new string unmapped field to the entity extension

It seems that you tried to implement a read-only virtual field, but you’re not doing it right. initValue() is a completely wrong method for this purpose, you need postLoad().

There is no PostLoad() as part of methods in the extension entity. We tried inserting the code snippet for all the methods available inside entity extension.

Let me know if you need more info

Thanks,

Shanakr :slight_smile:

If you were developing a custom entity, you would use postLoad(), as explained at the documentation page I linked above.

Because you’re making an extension, simply subscribe to an event. Notice that each entity offers onPostingLoad and onPostedLoad events.

Thanks for your reply martin

[DataEventHandler(tableStr(SalesOrderHeaderEntity), DataEventType::PostingLoad)]

public static void SalesOrderHeaderEntity_onPostingLoad(Common _sender, DataEventArgs _eventArgs)

{

SalesOrderHeaderEntity so;

so.Testing = “Testing”;

}

I tried the above event handler with my code. I also made sure that testing column is created in staging table as well in the extension. I also checked they are mapped correctly.

but still the testing doesn’t show the above assigned value when export out of ax to EXCEL in data management

Thanks,

Shankar

Of course that it has no effect. Your code merely assigns a value to a local variable, which is destroyed as soon as your method ends and it has no effect at the actual entity. You should cast the sender variable to the appropriate type (SalesOrderHeaderEntity in your case) and set the value there.

Thanks for your comment Martin.
Here is the code snippet:
[DataEventHandler(tableStr(SalesOrderHeaderEntity), DataEventType::PostingLoad)]
public static void SalesOrderHeaderEntity_onPostingLoad(Common _sender, DataEventArgs _eventArgs)
{
SalesOrderHeaderEntity x = _sender as SalesOrderHeaderEntity ;
x.Testing = “Testing”;
}
I still don’t see the value when I do an export to EXCEL/oData.
Can you point out what am i doing wrong?

Thanks,
Shankar :slight_smile:

I’ve built my own entity extension and did the debugging for you. The problem is that the event handlers isn’t called at all, unless postLoad() is overridden. Unfortunately that’s nothing we can fix - you’ll have to ask Microsoft to make sure the event is raised correctly.

Thanks Martin for all your help
We are not going to follow this approach anymore but if we do in future I will log a ticket with Microsoft