How to create a new Document programmatically in TypeScript

Hi,

I am trying to create a new document on the client side from a given model. I wonder if there are any ways to do that without a Form?

Thank you.

Hi,

the form-engine offers a Client DataProvider that creates a new document, fills in the initial values from the form model and then re-computes the document using the computation rules from the document model.
This is called “EmptyDocumentDataProvider” and available with the respective factory function “createEmptyDocumentDataProvider”.

Since you wrote that you want to do that without a form, there will be no initial values from the form model available. That leaves you with just an initial computation of the document (if you have any computation rules in the document model).

You can initialize your new document with an empty JS object and then run the computation on it as follows:

const initialDocument = {};
// validatorProvider refers to the generated code accessor of the document model
const documentService = DocumentRtServiceFactory.createDocumentRtService(validatorProvider);
const computationResult = documentService.compute(initialDocument);

const computedInitialDocument = computationResult.appliedTo(initialDocument);

If there’s another source of initial values, you can, of course, use that instead of the empty JS object in the beginning.

Thank you very much, That helps a lot