Init value in CDMs

Hi,

Our project has a requirement that we need “init value” for some fields in CDMs.

  1. We also need to init a value in a relationship document in CDM when “change_screen” to relationship screen or “add_row” in detached-repeated or any action that create a new document
  2. The harder thing is the init value calculated by client code, which means it’s a dynamic value.

How can I do that?

Thank you.

Hi @anh-round-summit,

From 20223.06-ext6 onwards, initial values may be set on Form Models that reference a CDM (A12-14696). There is a known bug with initial rows and this will be fixed for the next minor release (A12-16143). Please be aware that initial values are not supported on heterogeneous child documents (see here).

Initial values are always modeled as static values so as you mentioned, you need a slightly more complex solution.

I’m looking into a solution using a dependency to set a field value but I can’t get it to work yet… However, I can tell you that this is only likely to work if you are adding a row to a detached repeat and we would not expect this to work when using child activities.

If I have any more news regarding a modeling solution I’ll let you know.

Just to add some thoughts:
To transfer data into a ChildActivity you could use a HelperField in your CDM within the respective Relationship Element and calculate it. You then need a matching field in the DM you use for the ChildActivity.
If you want to calculate your dynamic data based on data in the root document, it is easier and cleaner to include the relationship back to the root into the CDM you use in the ChildActivity.

Our thought to write a dynamic value into a Field and keep it editable afterwards, was to use Form Model Dependencies. However, they need a user triggered change on the respective screen. So if you are ok that the user does not see the value right away, but only after a user-induced change on the DetailScreen/CA-form, you could model a workaround and it would work in the current A12 version.
If it should be shown right away you need Customization of the DetailScreen or A12-15397 for the ChildActivity form.

Hi @anh-round-summit,

did one of the replies answer your question or do you need further support?
If it is solved, please, use the checkbox to mark the solution to your problem so that other users also know what helped in your case.

Denise from the Discourse team

Thank you @malcolm-silver-ice and @felix-blazing-river,

I read all your comments and it looks like all solutions are a workaround. I understand why it is complicated and hard to implement.

I have an idea, that cdm team can consider to improve the init value:

I saw an action cdd/CHANGE_DOCUMENT dispatched when fill out any field in new child cdm document. It contains metadata for new doc like t_docRef, id, modelId, “meta-link-id”…
Maybe a12 can dispatch another action (after cdd/change) like “cdd/NEW_DOCUMENT_CREATED”, then we can use saga or middleware to catch that action and set a initValue we want.

Thanks for the suggestion! I will take it to the respective team.