I have to fields (First Name and Last Name) and I want to have a new field, that combine those for displaying on record. Or another work-around?
Anyone that knows how-to?
Hi Soren,
Lets break your need into two pieces:
-
Inserting a new record to database:
See here about our backend hooks, that can be used to alter/add information before saving into database. -
Fixing the existing database:
if you want to fix the data for existing database records, you can write a loop that goes over all of the items in the database in uses ’ update ()’ to edit the info.
Please note that ‘update()’ will erase unspecified fields so you should update with:
{
id,
firstName,
lastName,
firstAndLast: firstName + lastName
}
CAUTION: I would suggest running the function on a dummy database just to make sure you get the desired behaviour.
Hope this helps,
Liran.
I’m facing a similar problem.
I have a page to input data to create a new record in my collection, there is one field (age) that is calculated based on the input of another field (anniversary date), the age is correctly calculated and loaded in the input field (age) in the form, but when I save the record, this field in not saved to the collection.
Trying to solve this I have used the hook function, so I loaded the age into a local variable and use this in the hook Before_Insert to pass it to the item but still no success, can you help me identify what I’m doing wrong here.
Thanks.
PS: Posting some code below to provide more information.