Pass context in GUI annotations

I would like to pass the context $'ja' within the @default in the example below to the state 'Ja', but this isn’t allowed (Pseudo-code!):

'Postadres bekend': stategroup
	@default: switch >'Relatienummer' (
		| node as $'node' => switch $'node'.'Heeft postadres' (
			|'Ja' as $'ja' => 'Ja' // <-- define $'ja'
			|'Nee' => 'Nee'
		)
		| none => 'Ja'
	)
(
	'Ja' {
		'Adres': text
			@default: $'ja'.'Adres' // <-- use $'ja' here
		'Postcode': text
		'Plaats': text
		'Land': text
	}
	'Nee' { }
)

I guess I have to derive the 'Adres' all the way from the start, at switch >'Relatienummer'…?
Or am I lacking some knowledge?

Hi Tom,

The defaults do not depend on each other like that, they are per-property.
You should use the following:

'Adres': text @default: ^ >'Relatienummer'.'Heeft postadres'?'Ja'.'Adres'

By the way: are you referring to a 'Relatienummer' or to a Relatie?

If you are referring to a Relatie, I would usually name the property Relatie, the 'Relatienummer' happens to be way you refer to the Relatie, but the Relatie itself is what you are referring to, not to its number.

Application users refer to a customer (relatie) by both its name as its number (Relatienummer), therefore I chose to use Relatienummer as the key property and Naam as a (regular) property.

Considering your other remark:

You should use the following:

'Adres': text @default: ^ >'Relatienummer'.'Heeft postadres'?'Ja'.'Adres'

It is possible that >'Relatienummer' doesn’t exist, so the @default becomes this:

'Postadres bekend': stategroup
	@default: switch >'Relatienummer' (
		| node as $'node' => switch $'node'.'Heeft postadres' (
			|'Ja' => 'Ja'
			|'Nee' => 'Nee'
		)
		| none => 'Ja'
	)
(
	'Ja' {
		'Adres': text
			@default: switch ^ >'Relatienummer' ( // repetition of node switch
				| node as $'node' => switch $'node'.'Heeft postadres' (
					|'Ja' as $'ja' => $'ja'.'Adres'
					|'Nee' => ignore
				)
				| none => ignore
			)
		'Postcode': text
			@default: ... // repetition of node switch
		'Plaats': text
			@default: ... // repetition of node switch
		...
	}
	'Nee' { }
)

It looks very verbose to me, but there doesn’t seem to be a shorter way.

You can use an optional where rule:

'Postadres bekend': stategroup
	@default: switch >'Relatienummer' (
		| node as $'node' => switch $'node'.'Heeft postadres' (
			|'Ja' => 'Ja'
			|'Nee' => 'Nee'
		)
		| none => 'Ja'
	)
(
	'Ja' where 'ja' ~> >'Relatienummer'.'Heeft postadres'?'Ja' {
		'Adres': text
			@default: .&'ja'.'Adres'
		'Postcode': text
			@default: .&'ja'.'Postcode'
		'Plaats': text
			@default: .&'ja'.'Plaats'
		...
	}
1 Like

Hi Tom, it is possible that the Relatie does not exist, but that is no problem in gui annotations. Defaults are optional and do not result in a default value if references cannot be resolved, so

@default: ^ >'Relatienummer'.'Heeft postadres'?'Ja'.'Adres'

does exactly the same as you did in that more verbose way. The verbose way is only necessary if you want to have an alternative default when the Relatie does not exist, for instance.

My point about ‘Relatienummer’ is that I think is usually not a good idea to describe a reference with the key property of the object referenced. E.g. a Car might have a ‘Driver’, that might be referenced by the Person’s ‘Name’, but it would be strange and unclear to have a Car with a ‘Name’ as property, referencing this driver. Even if you understand that a Person is referenced, it is not clear if the Driver or Owner is referenced. In your case, your statements will read more clearly as well: > ‘Relatie’ . ‘Heeft postadres’?‘Ja’ makes more sense than a ‘Relatienummer’ having a postal address.

1 Like