How to access an object inside a $data (trick integrated with function)

Scenario: the variable $data is triggered by a trick automation that run a backend function. Right?

We have a table called ‘reservas’ and a table called ‘clientes’. They are connected by a field called ‘cliente’ in the table ‘reservas’.

The trick that we’ve setup is for the table ‘reservas’, and when it run the backend function we want to access the ‘cliente’ field value(s).

PS.: The trick works fine for something like $data[‘name’], where ‘name’ is an entry of type string or number. But it won’t work for $data[‘cliente’], where ‘cliente’ is a Connect table entry (object?).

Any ideias? Suggestions?

@vinicius.belnuovo Can u help Manoel?

Hey, @manoelpereiraeng

If I understood that correctly, you have a record Reserve which has a connect field that links it to a Client, and you want to get information from that linked client, right?

If so, the thing about the connected field is that it doesn’t contain all the information from the client (that would be really inefficient). It has only its id in the client table for reference. If you want that information, you have to search for it with Jestor.loadData().

So if I wanted to get the client’s email, for example, I’d have to do this:

$search = Jestor.loadData('clients',['where'=> ['id_clients' => $data['client']]]);
$email = $search[0]['email'];

The last line is basically saying: get the first result from the client search and then its email.

You can learn more about Jestor.loadData() here: Native Methods

You did understand correctly. And we were already trying with the Jestor.loadData(). We just can’t quite access it yet, we can’t find the correct way to query it.

We tried your code and it didn’t work. Is the following piece of code correct?

['where'=> ['id_clients' => $data['client']]]);

We logged the $data['client'] and the return is an Array. Don’t seem to be an id :thinking:. Thus, we can’t complete the query.

This would make more sense (but it doesn’t work either):

['where'=> ['id_clients' => $data['client']['id_clients']]);


Hey @manoelpereiraeng

Sorry for the late reply!

I think I understand the problem now, it didn’t click at first that this was a back-end function getting data from a trick. In that case, connected fields do bring the info from the connected record, but as an object.

This should work for getting the client’s email, for example:


I could use the hypohetical code below to get the client’s name and reservation code, and assemble a text with them in the $msg variable, for example:

$name = $data['client']->name;
$res = $data['res_code'];
$msg = "Client $name made the reservation $res" 

So there’s actually no need to fiddle around with loadData(), as long as the info you need is in the first layer of client data :slight_smile:

As a side note, you can pass info back to the trick sequence if you need (for example, if you wish to use the Gmail trick). All you have to do is pass an array or variable back through the front-end (as such)

Then you can use the value of $response on the next trick:

Hope that helps!