Providing a DataLoader for empty documents

We need to initialise empty documents upon creation with certain values depending on the logged-in user. For this purpose, we have identified a custom DataLoader to be the appropriate place to implement this.

We want to do this only for certain models, while relying on the EmptyDocumentDataProvider returned by ApplicationFactories.createEmptyDocumentDataProvider for all others.

The problem: according to the BAP documentation, DataProviders are always loaded before any DataLoaders.
To my understanding, this makes it impossible to use a DataLoader for a new empty document instance while also using createEmptyDocumentDataProvider.

I noticed there are some internal methods that would seem like they could help use (e.g. createDataProviderForDataLoader – we could create a data provider “wrapper” for a custom empty document data loader that could then be mounted before the EmptyDocumentDataProvider is loaded), but alas, these are unexposed.

What would be the best way to solve this?

In my opinion, DataProvider is a more appropriate place to implement your requirement as :

  • It’s newer API.
  • Able to do almost everything that DataLoader can do
  • Run before data loaders

Therefore, you should create your own DataProvider and register it in your appsetup like the following snippets:
image
Also be aware that BAP Client go through the registered list of DataProvider in index order and get the first data provider which have canHandler() return true. Therefore, you should put your custom DataProvider before the default EmptyDocumentDataProvider and make the canHandle() return true only when it’s needed (e.g the certain models matched)

Hi Vu, thanks for your advice.
If we want to do it entirely with a DataProvider, I see the problem of implementing the necessary logic to create and initialise the empty document etc. BAP of course already has this logic internally and uses it in e.g. createEmptyDocumentDataProvider, but the functions aren’t exported. Is there any way to have BAP create the empty document first and then work on it to initialise?

Hi Marcel,

With the BAP Form-Engine 28.1.0 we will provide a utility function to creat and initialise an empty document.
You can use this function in the BAP Client in version 6.1.0 to create an empty document. You then only need to make sure
that you add a document id (for new documents you can use the constant NEW_INSTANCE_IDENTIFIER) and model id to the document.

The related JIRA ticket:
<INTERNAL_LINK>

I hope this helps you.