Creating stategroup based on existence of value in collection

I am trying to figure out whether it is possible to create a stategroup based on the existence of a value in a collection. The syntax below does not work because .‘Certifications’ is not a node, but it gives you a reference of the solution I am looking for.

'Global Gap Certified Product': stategroup = switch .'Certifications' is ( ^ .'Relationship Management'.'Global Gap' ) (
					| node => 'Yes' ( )
					| none  => 'No' ( )
				) (
					'No' { }
					'Yes' @desired { } // zowel ggn als supplier heeft certification
				)
				'Certifications': collection ['Certification'] = >'GGN'.'Certifications'* {
					'Certification': text -> ^ >'GGN'.'Certifications'[]
						where 'Supplier' ~> ^ ^ ^ >'Supplier'.'Certifications'[]
						= key
					'Valid': stategroup = switch .'Certification'&'Supplier' (
						| none => 'No' ( )
						| node => 'Yes' ( )
					) (
						'No' { }
						'Yes' @desired { } // zowel ggn als supplier heeft certification
					)
				}

If you have a link ~> to an entry in the collection you could switch that.

'Global Gap Certified Product': stategroup = switch  ^ .'Relationship Management'>'Global Gap' ( 
  | node => ...

This works, but I am not sure whether it is the most efficient way :joy:

'Global Gap certified count': number 'count' = count .'Certifications'* .'Valid'?'Yes' .'Global Gap Certification'?'Yes'
'Global Gap Certified Product': stategroup = switch .'Global Gap certified count' compare ( 0 ) (
	| > => 'Yes' ( )
	| <= => 'No' ( )
) (
	'No' { }
	'Yes' @desired { }
)
'Certifications': collection ['Certification'] = >'GGN'.'Certifications'* {
	'Certification': text -> ^ >'GGN'.'Certifications'[]
		where 'Supplier' ~> ^ ^ ^ >'Supplier'.'Certifications'[]
		where 'GAP' -> ^ ^ ^ ^ .'Relationship Management'>'Global Gap'
		= key
	'Valid': stategroup = switch .'Certification'&'Supplier' (
		| none => 'No' ( )
		| node => 'Yes' ( )
	) (
		'No' { }
		'Yes' @desired {
			'Global Gap Certification': stategroup = switch ^ .'Certification'&'GAP'  (
				| node => 'Yes' ( )
				| none  => 'No' ( )
			) (
				'No' { }
				'Yes' { }
			)
		} // zowel ggn als supplier heeft certification
	)
}

Figured out this is also possible:

'Global Gap Certified Product': stategroup = switch .'Certifications'* .'Valid'?'Yes' .'Global Gap Certification'?'Yes' (
	| nodes => 'Yes' ( )
	| none => 'No' ( )
) (
	'No' { }
	'Yes' @desired { } // zowel ggn als supplier heeft certification
)
1 Like