Solved

Unable to cast object of type 'PX.Objects.CR.BAccount' to type 'PX.Objects.EP.EPEmployee'.

  • 17 November 2023
  • 1 reply
  • 85 views

Userlevel 7
Badge +8

Hello all,

 

I have come across a wierd situation. In my extension to “EPWeeklyCrewTimeEntry” screen “EP307100” I simply want to rename one of existing grid columns to match with my import excel file column name. So I have added a CacheAtached event that works fine. Column is renamed, user does normal data entry, saves and so on. The problem I am facing surfaces itself when I use “Upload” button to import from Excel. The uploads works as meant to work and imports all data correctly BUT at the end shows a dialog saying “Unable to cast object of type 'PX.Objects.CR.BAccount' to type 'PX.Objects.EP.EPEmployee'”. If I click OK I still can save the imported data without any issue but after spending couple of hours, I can’t seem to figure out why this errors is thrown at the end when everything is imported correctly. If I comment the event code I do not receive this error. I have tried both old and new syntax, tried Append, Merge and even Replace the attributes and on all of them I get the same error. This is the simple event code:

#1 Generic Method
[PXMergeAttributes(Method = MergeMethod.Append)]
[PXCustomizeBaseAttribute(typeof(PXUIFieldAttribute), nameof(PXUIFieldAttribute.DisplayName), "Employee Id")]
protected virtual void _(Events.CacheAttached<EPActivityApprove.ownerID> e) { }

#2 Traditional Method
[PXMergeAttributes(Method = MergeMethod.Append)]
[PXUIField(DisplayName = "Employee Id")]
protected virtual void EPActivityApprove_OwnerID_CacheAttached(PXCache cache) { }

Any help is apprciated.

icon

Best answer by aaghaei 18 November 2023, 00:53

View original

1 reply

Userlevel 7
Badge +8

I couldn’t figure out why this is done but I found the culprit. There is a method “PrepareImportRow” that somehow, someone for some reason which I couldn’t figure it out, has user BAccount in this method instead of EPEmployee which is used all over the graph code. I wrote a Delegate to override this method and all is good now.

Reply


About Acumatica ERP system
Acumatica Cloud ERP provides the best business management solution for transforming your company to thrive in the new digital economy. Built on a future-proof platform with open architecture for rapid integrations, scalability, and ease of use, Acumatica delivers unparalleled value to small and midmarket organizations. Connected Business. Delivered.
© 2008 — 2024  Acumatica, Inc. All rights reserved