Set current date when the field is rendered

Hello,

we have a requirement that needs the following functionality:

A date field should be set to the current date as soon as the related form model field is rendered in the UI. The value of the date field may not change after that.

Use case example: A user creates a form. In the form, there is a field “creation date” which is automatically filled in with the current date.

Can we model this with the SME alone or do we need custom code to fulfil this requirement?

Thanks in advance!

Hi @daniel-radiant-elm,

This is a modeling approach,
Try adding a new computation for “create date” without precondition
and put this “DateFromDateTime(Now)” into the calculation.

Hope this helps!

When the document is first created, this will set the current date into the field.

However, when you reopen the document, the current date will again be set and thus update the field.

@ben-keen-aspen @erik-radiant-gorge
Would it work when we check if the field is filled with an extra computed field? The extra field just checks, if the createdAt-Field is filled. If not filled, then set it to false and if its field, then set it to true. The computation of the createdAt-Field then has a precomputation to check if the extra field is false and if its false, then compute the current date. I add an example of what I mean:
Test.json (2.9 KB)

That’s a cycle and is not allowed because it would lead to endless loops.

I think there’s currently no way to solve this with just modeling.

Okay, then we will find a solution with custom code. Thank you for your replies @erik-radiant-gorge @ben-keen-aspen!