How to get a model's parent in the UI Designer?

1
0
-1

Hello,

I am working on a form and I need to load a model's parent. In theory I would be able to load the parent model by dragging the appropriate data model from the UI Designer and querying by persistence_id using the child's parent_persistence_id attribute, but this attribute does not seem to load in the UI Designer, even though I have confirmed it exists by browsing data on the H2 database. The model's relationship is set as congregation because setting it as aggregation seems to generate a bug when it comes to creating the contract for the parent model and the child models. They are also set to always load related objects

Any help would be appreciated

3 answers

1
0
-1
This one is the BEST answer!

I was able to solve my issue by manually saving the object's parent ID as an attribute. I achieve this by using a system task, in which an operation on my Parent Object, "RegistroTitular" is set to "setDerechosMineros(list)".

This operation is a Java method that is automatically generated by Bonita once I add my BDM data to the Pool Variables. The method takes two parameters, the particular Parent Object whose Child Objects we will manipulate, in my case "RegistroTitular", and the new list of Child Objects, in my case "DerechosMineros", that will be saved.

The first parameter is self explanatory, I will use the Parent Object that is used in the instance variable. For the second parameter, I used a Groovy Script to generate an array from the list of Child Objects that already exists, iterate through each element in this new array, and save the Parent Object ID as a BDM attribute.

What the Groovy Script returns is a list/array of Child Objects as defined in my process instantiation form, with the addition of a LONG attribute that references its Parent Object.

Now, every time I load a Child Object, its JSON representation includes a reference to its Parent Object, allowing me to query for the Parent Object in the UI Designer.

1
+1
-1

Hi Miguel,

could you please answer a few questions regarding your BDM model?

RegistroTitular objects does have sense without DerechoMinero? Can it exist without it?
DerechoMinero objects does have sense without RegistroTitular? Can it exist without it?

As far as your shared images, I see that you have set:

RegistroTitular has in composition a list of DerechoMinero objects. This means that DerechoMinero have no sense without being attached to a RegistroTitular . It is same use case as an Invoice (RegistroTitular ) and its InvoiceLines (DerechoMinero)

And what you expect is to retrieve a RegistroTitular form an DerechoMinero. This is not fesable by using BDM APIs and Custom queries (as far as I know). That attribute is internal and not returned in the JSON representation of the object. But you can do always a REST API extension to query directly the database.

In the other way around, if you set that DerechoMinero has in agregation a RegistroTitular, then you can do it using APIs

Comments

Submitted by miguel.aguilera... on Wed, 04/08/2020 - 22:40

Hola Pablo,

Gracias por tu respuesta. Al final, logré guardar en DerechoMinero la referencia al RegistroTitular al que pertenece usando un system task, que por medio de una operación asigna como atributo el ID de RegistroTitular a cada elemento de la lista de DerechosMineros. De esta manera, la representación JSON de un objeto DerechoMinero siempre "carga" una referencia a su RegistroTitular.

En cuanto a tus preguntas, un RegistroTitular debe tener por lo menos 1 DerechoMinero, y 10 como máximo. DerechoMinero no debería existir sin un RegistroTitular.

Nuevamente, gracias por tu respuesta.

Saludos

-

Hello Pablo,

Thank you for your response. I was finally able to save a reference in DerechoMinero to the RegistroTitular to which it belongs by using a system task that uses an operation to assign the RegistroTitular's ID as an attribute to every element in the list of DerechoMineros. This way, the JSON representation of the DerechoMinero object always loads a reference to its RegistroTitular

Regarding your questions, a RegistroTitular must have at least 1 Derecho Minero and 10 at the most. DerechoMinero should not exist without a RegistroTitular.

Once again, thank you for your response.

Regards

1
0
-1

HI Miguel,

Could you please post your bdm and a simple page that shows what you plan to do. I not clearly understand what are your issues

Thanks in advance

Comments

Submitted by miguel.aguilera... on Mon, 03/23/2020 - 19:03

Hi Pablo,

https://imgur.com/a/0iN9e9l

Here is a link to an album where I share some BDM screenshots and an explanation for what I'm trying to do. I hope it helps to clear up what I'm trying to achieve.

Please let me know there's anything else I can do to further explain my objective.

Regards

Notifications