If... then... (no) else in Microflow Expression?

0
I want a Microflow to create a new object-record. Depending on the values stored in "example" records in the object "template", I want the Microflow to complete this new record with the same values for each member (field). In case the value is empty in that template record, I want to keep the default value (set in the Domain Model). So I created a Microflow, at one point I come to a 'Change Object' component, with for each Member a line with a "if-then" expression like (here it is for the member "priority"): if $SelectedServiceRecord/TemplatePriority != empty then $SelectedServiceRecord/TemplatePriority else Module.Priority.PRIO020_MEDIUM (Priority is an enumeration) As you see, I am repeating here the domain model default value as a hard coded value. That's not nice: if this default value changes in the domain model, I should not forget to change it in this microflow too (no doubt that I will, but that is not the question, I'm not on mental coaching consultancy here...) I appearently cannot write the if..then without else: Mendix seems not happy, and requests to continue with an "else" statement. I see an alternative: working with a split for each member, and calling a change object only if the value is not empty in the template. Is there a better (shorter) alternative?
asked
3 answers
2

Hmm I do not agree on the proposal for a few reasons:

  1. If a read a change as non experienced Mendix modeler, it is clear what if-then-else means, while for only if-then I would need to look up in the documentation what is done in the else case.

  2. If I saw 'if X then Y' without else, I would expect it to not change the current value in the else case, rather than changing it to the default.

  3. If I'm reading such a microflow, I have to look up in the domain model to which value it will change in the else case.

  4. If I search on 'Module.Priority.PRIO020_MEDIUM' (the default value), I would not find this change since that value is set implicitly instead of explicitly.

Regarding your alternative, that means its no longer possible to change to an empty value?

answered
2

A feature request to Mendix could be a function called 'defaultvalue($entity/attribute)' that returns the defaultvalue() of the attribute it is trying to set.

In this case you register the default values in 1 place and still can use the if .. then .. else default_value($entity/attribute)

(In splits I would also appreciate a previousvalue($entity/attribute) and ischanged($entity/attribute), but that to the side).

answered
1

Make sure that the template $SelectedServiceRecord/TemplatePriority has a default value and create a template when it does not exist (in a MF do a retrieve and noting found create an object).

Remove the 'if then else' from the assignment just assign the value from the templaterecord

answered