Derive `@max` value within action

I use an action to create a sibling entry in a collection with an acyclic-graph constraint. In this action the user has to provide a number of pieces. The maximum allowable number of pieces to be provided is determined by:

  • the number of pieces in the current entry, from which the sibling will be created
  • the in the action provided way of dividing units of the current entry
  • the in the action provided factor in which units of the current entry should be divided

Here my boiled down code sample (incomplete!!) :

'Maak deelpartij': action {
	'Versnijd-sleutel': stategroup (
		'Volgens model' { }
		'Vrij te kiezen' {
			'Eenheid versnijd-sleutel': stategroup (
				'Stuks per kaas' {
					'Versnijd-sleutel': number positive 'stuks per kaas'
				'Stuks per stuk' {
					'Versnijd-sleutel': number positive 'stuks per stuk'
	'Aantal nieuw model': number positive 'microstuks'
		@max: switch @ .'Versnijd-sleutel' ( // <-- this `switch` is not allowed!
			|'Volgens model' as $'model' => switch ...
			|'Vrij te kiezen' as $'vrij' => switch $'vrij'.'Eenheid versnijd-sleutel' (
				|'Stuks per kaas' as $'kaas' => product ( ... , ... )
				|'Stuks per stuk' as $'stuk' => product ( ... , ... )
} => update ^ .'Partijen'
	= create ( ... )

I can’t create a derivation to be used by the @max annotation, since it’s inside an action.
I need the action to properly create the sibling entry.
How to deal with this situation?

Unfortunately there is no way to express that right now. We plan to add support for the switch soon, in a new language version.

You should consider whether this maximum is clear when it is calculated like this. The user might need to see the maximum somewhere as well. That can be achieved by writing a derivation for the maximum and then using that as the input for your @max: expresssion.

In the end I solved it like this, which also better suits my model:

'Maak deelpartij': action {
	'Datum': number 'datum'
		@default: from 'datum-tijd' now
	'Model': text -> ^ .'Beheer'.'Applicatiebeheer'.'Modellen'[] .'Type model'?'Productie'
	'Versnijd-sleutel': number positive 'stuks per stuk'
		@default: switch @ >'Model'.'Versnijden' (
			|'Ja' as $'versnijden' => switch $'versnijden'.'Snijmethode' (
				|'Automatisch' as $'automatisch' => $'automatisch'.'Versnijd-sleutel'
				|'Handmatig' as $'handmatig' => $'handmatig'.'Versnijd-sleutel'
			|'Nee' => 1
	'Gewenst aantal': number positive 'stuks'
		@description: "Rekening houdend met beschikbaar aantal en versnijd-sleutel"
		@max: product ( .'Resterend aantal' , @ .'Versnijd-sleutel' )

This means I first derive the default Versnijd-sleutel and can then derive the @max value.
I would like to add the max value in a concatenation within the @description of Gewenst aantal, but that’s not possible at this moment.