Skip to main content
Answer

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

  • November 17, 2023
  • 1 reply
  • 447 views

aaghaei
Captain II
Forum|alt.badge.img+10

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.

Best answer by aaghaei

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.

1 reply

aaghaei
Captain II
Forum|alt.badge.img+10
  • Author
  • Captain II
  • Answer
  • November 17, 2023

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.