Issues Importing in Custom Entity

Hello,

I had a requirement to create a copy of the Expense Journal Line entity in order to add fields from several ISVs that we are using. We chose to duplicate the entity instead of modifying the standard one to avoid affecting standard functionality. I named the new entity ISVExpenseJournalLineEntity.

To support this, I:

  • Added a PostLoad() method to map class values to entity fields.
  • Included TaxJournalLineEntityHelper in my solution, since it was a private class and couldn’t be accessed otherwise.
  • Added the data method used by the ISV to calculate one of their fields onto the entity.

Everything built successfully, and I was able to export data using this entity without issues. However, when trying to import data via the Data Management workspace, I get the following error:

Unable to cast object of type ‘Dynamics.AX.Application.ISVExpenseJournalLineEntity’ to type ‘Dynamics.AX.Application.ExpenseJournalLineEntity’.

I have checked my code and don’t see any direct references to the old ExpenseJournalLineEntity. I also tried:

  • Regenerating the staging table
  • Running a DB Sync

Neither resolved the issue.

My Questions:

  1. What could be causing this type casting error?
  2. Could there be any hidden dependencies still linking my entity to the standard one?
  3. Could the ISV’s data method or any inherited logic be causing this issue?

Any help or insights would be greatly appreciated!

Duplicating an entity should be the last resort, because it’s very expensive. On every update, you must check whether Microsoft didn’t change the entity or anyone didn’t extend it (usually ISVs, but it could be Microsoft as well) and incorporate changes you your copy. If you fail doing that, your logic will divert from the standard logic and your entity may work incorrectly or stop working completely.

In your case, the ISVs should have extended the standard entity. Ask them to do so; resort to a customization and take a responsibility for maintenance of the solution only if the ISVs refuse to do that.

You seem to think that you have just two options: extending the standard entity and duplicating it. But that’s not the case. If you’re sure that extending the entity is impossible, you can create a new entity without duplicating the standard one: you can use the standard entity as a data source of your new entity.

If you insist of using the duplicated entity, use the debugger to find where the exception was thrown.

Hi Martin and Karl,

I have a followup question to the original answer - If duplicating an entity is an expensive endeavor, how do handle the situation where an extension does not generate the desired result? The situation I found myself needing to duplicate an entity was for SalesOrderHeaderCharges because even in extension, it would not allow me to assign public collection names so it could be accessed via odata and we needed it for odata integration from another system.

Thank you, Margie

Hi Martin,

The ISV does extend some of the tables used in the entity, such as LedgerJournalTrans_Project. The requestor specifically wanted one of the fields from this table to be added to the entity so they could pull it into the Excel entity export on the General Journals page.

I originally tried to use the standard entity as a data source for my custom entity, but I kept running into this message:

Since I wasn’t able to work around that, I opted to duplicate the entity instead.

I’ll go ahead and debug the issue, but I wanted to get your input—do you think duplicating the entity is what’s causing the import issue? Could there be internal references within the duplicated methods that are leading to this error?

Would appreciate any thoughts!

Margie: This is another example where you can use a composition - creating a new data entity with the standard entity as a data source.

Karl: Such entities can be created and work fine. You’re either incorrectly trying to create an entity for the staging table, or you just run to a limitation (one of many!) of the wizard. You still can create the entity manually. I don’t remember if I ever tried to use the wizard to create an entity for an entity; I wouldn’t be surprised if it can’t handle that.

Hm whenever I try to create a new entity it pretty much forces me to use the Wizard. That’s when I tried to use the entities staging table. Is there another method for working around this?

You can either duplicate an existing entity or chose an arbitrary table in the wizard. Then remove everything from the entity and add a data source and fields manually.