Computation of a field only one time / if it has NULL value

I have a fairly trivial task: I want to set a date-field to TODAY but only once. Once set, the value should not change anymore. Since references to the field itself are not allowed in the precondition for whatever reason, I don’t find a way to achieve this. Does anybody have an idea on how to solve this?

Would it be possible to use the new mapping tooling for that? You map a document of model A to another document of Model A copying all the fields. But since source and target are different documents I would think that there is the potential for using a precondition that the source document field is empty or not.

The Project is not on the release in which the mapping model can be used. Also, mapping models are currently experimental and not stated as productive.

Hi @tobias-gentle-alder

We’ve been aware of this sort of requirement for quite a while and the following tickets are open:

  • A12-11467 - Configure when to trigger computations that depend on NOW or TODAY
  • A12-11374 - Trigger of Validation and Computation
  • A12-13865 - Allow initializing fields using expressions

There’s already a similar post with a solution:

So, it’s not currently modelable but you can do this with custom code.

One of the above tickets could provide modelable solution, alternatively we’re also looking at modeling solutions based on Document Metadata. For example, you compare with the “createdOn” Metadata Field which is already set once and then never changed.

Thanks for the reply. I hoped to find a solution without having to patch it in the code. I will look at the metadata proposal otherwise bite the sour fruit.

Just to be clear…
Modeling Rules that reference Document Metadata is also an open requirement and not yet modelable.

You will need custom code either way.

I’m not sure, however, if it’s easier for you to:

  • code a custom condition that looks at the Document Metadata

or

  • code a custom saga to set a Field Value

Right, I have just seen that. Okay, I will look into custom conditions.

fyi Modeling & Development MMH: Custom Condition

Hm I don’t see how Custom Conditions could help with field initialization since I cannot set a value there. then saga it will be I assume

Hi @tobias-gentle-alder

What I was trying to say is that the “createdOn” Metadata Field is already set on document creation.

You did not specify when the you want to set the date field when you said,

If you are setting this field on document creation, then you already have this data in the Metadata.

You also didn’t say why you wanted to save the Today value once and then hold it.

If you want to use this value in Validation Rules, then you could try and use a Custom Condition.
If you just want to display this value, you can display Metadata in the Form Model and Overview Model per-default

This solution will not work for other use-cases:

  • You are setting the TODAY value to a different time to the “createdOn” Metadata
  • You want to use this value in Computation Rules

What I should have said ist that I want to initialize a date-field with the value of TODAY. That seems not possible in a computation since the field will change on any update of the document. Metadata createdOn is no option BTW because the field-initialization is not happening on document creation. Anyways, Ill go the saga route

Meanwhile, gaining a better understanding of the core concepts of A12, I believe that the purpose of the Kernel-Language in A12 is solely the intrinsic validation of A12 documents for consistency and NOT a DSL to enrich documents with derived or otherwise calculated properties that should be maningful for external business-logic. I believe ther is confusion about this among modellers and developers, it would be good to clarify this. Am I somehow right with my interpretation or wrong?