Skip to main content
Asked a question 2 years ago

How to create dynamical SemQL function which drills down entity and returns specific record? Case: Car has always Contract. When creating Car, user chooses whether the ownership is X or Y. When user chooses ownership X, I want to choose automatically Contract Z and fill it in FID_contract field. There is only one contract (Contract Z) for ownership X and I want to get this Contract Z's UUID automatically in FID_Contract. It is quite easy to hard code, but in the development period UUID will change.

Where am I?

In Semarchy Community you can ask and answer questions and share your experience with others!

Hi Valtteri,

if my understanding is correct, Contract and Ownership are both parent entities of Car.

In this case, you could create an enricher with None as scope and trigger this enricher On Data Change during the form step. This enricher will fill FID_Contract with this kind of expression:

case when
		distinct_count FID_Contract
		from Ownership.Cars80
	= 1
		first FID_Contract
		from Ownership.Cars80

This means that if only one distinct Contract is associated with the selected Ownership, then we take the first one to fill current FID_Contract.

I hope this helps.

Best regards,