Moin everybody,
I want to update an IFieldInstance in a document, and I have question on how documents are initialized. During debugging I’ve observed, that some entity instances are present in my document, filled with null values.
My code to update an IFieldInstance:
@Override
public <T> void findFirstFieldInstanceSetValue(IDocument document, String path, T value) {
document.getEntityInstances().stream()
.filter(ei -> ei.getPath().equals(path))
.map(IFieldInstance.class::cast)
.findFirst()
.ifPresent(fi -> fi.setValue(value));
}
Should we always check if the field instance exists in the document, and if not create it with IDocumentFactory#createFieldInstance and use IDocument#addEntityInstance to add it to the document?
What is the recommended way, in order to update a field instance in a document?