I’m now working on a ticket to custom the component. I want to add a preview button on it based on an annotation. I add a provider to the FormModelControl like this:
<CustomFormControlContext.Provider
value={{
modelElement: props.modelElement,
config: props.config,
documentPath
}}
>
<DefaultFormModelMap.Control.component {...newProps} />
</CustomFormControlContext.Provider>
and then I try to render the component by finding the annotation like this:
if (FormControlContext?.modelElement.annotation?.find(annotation =>
annotation.name === AnnotationConstants.ENABLE_PREVIEW_BUTTON_ANNOTATION)) {
return <MyComponent .../>
}
My function will work when I add the annotation to the Form model but with the Document Model it’s not.
So I want to know if there is any way for FE to use the annotation from the Document Model.
Thank you.
hi @vinh-neural-shore,
since you have access to the document entity path inside your control you should be able to use kernels DocumentService.getAssignedObject(document, entityInstancePath) from DocumentServiceFactory to get the field object containing the annotation.
HINT: if you do not have the entity instance path you can get it by famous useDocumentPathForInput hook of form engine
Hi,
Thank you for your answer. I have already can get the object, but my question is how to know if that element has the annotation when I add the annotation to the Document model (it works for me now when I add it to the Form model)
Sorry, i misunderstood before. in your case you need the:
DocumentModelSearchService.getByPath(modelPath) from the DocumentServiceFactory then you will have access to the element object which contains the annotation
^modelPath is of type ModelPath, in fact the entitiy instance path without index
Thanks for your answer, I will try it
Hey @vinh-neural-shore,
did you succeed with the help of the answer provided?
Hi nschwarzenberger, while dicussing on the topic we found another solution and it worked so I decided to follow it. I haven’t tried your solution mschmahl solution yet. But anyway, thanks for all the support