About relookup() method under controller

What actually the rellookup method does?

Performs a relookup on the current record of a value that is based on a relation and
has an auto-enter data setting (in Dataproviders > Properties).

This can be handy if you want to store historic data. Say for instance, you need to store the customers’ name and address at the time an order was issued. You could store that data in the order table, copying it from the customer table every time a new order record was created.

Servoy enables you to define that the order.customer_address field is a copy of customer.address, for instance. With relookup, this data is automatically copied from the original.

svroemisse:
Servoy enables you to define that the order.customer_address field is a copy of customer.address, for instance. With relookup, this data is automatically copied from the original.

That mean it will work as a trigger?
When a new record is created in the order table automatically address field from the customer table is copied to the order table.

But How can we do that?

No, you have to call the relookup method for the data to actually be copied. Or you can select relookup from the menu.

svroemisse:
No, you have to call the relookup method for the data to actually be copied. Or you can select relookup from the menu.

Can you give a sample code for this?

Thanks.

This:

forms.order.controller.relookup()

will perform a relookup on the order form, meaning that all fields that have been defined as relookup fields will be filled with the current value that’s in the related customer record from the example above.

To sum it all up:

  • in Dataproviders > Properties, you can define a field to be a relookup value of a field in a related record (say order.customer_address is a copy of customer.address)
  • by performing a relookup on a form -either in code or via the menu- you can copy the fields as defined above (the current value from customer.address is copied to order.customer_address)

Or in other words: a lookup copies the defined value when the record is created (or if the field needed for the lookup changes - for example a customer ID). If you want to update such a value at a later time, you use relookup.