In order to process a document that is loaded or saved in the BAP Client, we need to call the kernel APIs:
DocumentServiceFactory().getDocumentService().formatDates(document, documentModel),
DocumentServiceFactory().getDocumentService().removeTransientFields(document, documentModel)
or
DocumentServiceFactory().getDocumentService().parseDates(document, documentModel),
DocumentServiceFactory().getDocumentService().addTransientFields(document, documentModel)
This step is typically done in a data provider when the document is loaded or saved. However it is not guaranteed that the documentModel is already loaded in a data provider when trying to call these functions.
As far as I know it is not easily possible to suspend the data provider until the models are loaded, since the information which models are necessary is not passed to the data providers.
Of course one could solve this problem manually for each data provider but this is a lot of work for large code bases.
Is there some workaround for handling this problem?
Hi, you can use a function waiForStateChange in StoreSagas to get documentModel when it loaded
This is a sample code in my project
const documentModel: DocumentModel | undefined = suppressError(
yield call(() =>
StoreSagas.waitForStateChange(ModelSelectors.modelLoaded("DocumentModelName", Model.isDocumentModel))
)
);
function suppressError<T>(resultOrError: { readonly model: T } | Model.Error | undefined): T | undefined {
return resultOrError && !Model.Error.isInstance(resultOrError) ? resultOrError.model : undefined;
}
It can be used to get FormModel as well.
Hope that it can help you.
Thanks for your reply.
Yes this works to wait until the document model is loaded but you still have to specify the name of the document model, so this solution only handles the issue for a single data provider.
Im looking for a more generic solution though.
I am not sure for a generic case that DataProvider can detect “Which DocumentModel are using?”.
But you can simply push DocumentModelName into descriptor (of activity). Then you can get it via config.
The requirement ticket A12-15081 has been created for this issue.
Update: The ticket for thi (A12-15081) has been released in 2024.06 with Client version 15.0.0.