After injected a button in the material defect view, there has an error

Hi,

I used the extends method to add a button to the material defect view action bar.


But when clicking the defect item which used picture, it will call a service LoadObjectRelations, and will has the follows error.

So I want to ask if you anyone can help me with this?

Thank you very much.

Hi Erchuang,

Your button injection code itself looks fine: PageCustomMaterialDefectsViewComponent extends PageMaterialDefectsView, calling super(...) correctly, and the new MedDev.MaterialDefect.ManageProtocol action button added alongside the existing ones in the overridden template — that’s a supported pattern and I do not think it is what’s causing the error, altough I would recommend to prefer the usage of a custom MetadataService ( check details here ).

The network/console screenshots show: POST /api/GenericService/LoadObjectRelations is returning a 500 with a JSON deserialization exception:

Type specified in JSON 'Cmf.Foundation.BusinessObjects.EntityDocumentation, ...'
is not compatible with 'Cmf.Foundation.BusinessObjects.Abstractions.ICmfFile, ...'
Path 'Object.Picture.$type', line 1, position 1717.

So, I think the server is trying to deserialize the defect’s Picture relation as ICmfFile (which is what MaterialDefect.Picture is supposed to be — a CmfFile reference), but the object actually stored/returned for that relation has $type = EntityDocumentation. EntityDocumentation is a different business object (used by the Documents/attachment-versioning feature), and it does not implement ICmfFile — hence the incompatible-type error. This is a server-side data/type mismatch, not something your Angular customization is causing.

A few things worth checking:

  1. Does the same 500 happen on an out-of-the-box Defects view (no customization at all) for that same defect? That will confirm it’s unrelated to your button.
  2. How was the picture on that defect originally captured — through the standard defect recording flow, or through some other integration/import that may have linked a Document entity instead of a CmfFile?
  3. Check the MaterialDefect record’s Picture field value directly to see what business object it actually resolves to.

Regards…

Hi Joao,
Thank you very much for your reply.

In fact, I have tried the to inject a button to the action bar first, but this way doesn’t match the requirement, because the injection button will display on all the views, so I used the current method.

About the checking:

1 This error doesn’t happen if no customization. It’s only occuring after added this button.

2 After upload a image, then click these icons.

3 It seems it’s a base64 object