Skip to main content
Question
Anonymous
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
	lookup
		distinct_count FID_Contract
		from Ownership.Cars80
	end
	= 1
then
	lookup
		first FID_Contract
		from Ownership.Cars80
	end
end

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,

Stéphanie.