Start a new topic
Answered

Dynamic SemQL function to drill down entity and return a record

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.


Best Answer

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.Cars
  end
  = 1
then
  lookup
    first FID_Contract
    from Ownership.Cars
  end
end<span class="fr-marker" data-id="0" data-type="false" style="display: none; line-height: 0;"></span><span class="fr-marker" data-id="0" data-type="true" style="display: none; line-height: 0;"></span>


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.

1 Comment

Answer

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.Cars
  end
  = 1
then
  lookup
    first FID_Contract
    from Ownership.Cars
  end
end<span class="fr-marker" data-id="0" data-type="false" style="display: none; line-height: 0;"></span><span class="fr-marker" data-id="0" data-type="true" style="display: none; line-height: 0;"></span>


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.

Login to post a comment