Dear All,
I’m trying to build a hook for my collection called ‘memberCollection’ with a beforeInstert function. I managed to get the year and the month from a ‘Time and Date’ field called ‘date’ but I struggled with the user name what I try to get from the userInfo of the content owner.
There are no runtime errors when the code runs and the console log function gives the expected result, BUT my collection field ‘name’ doesn’t update while ‘year’ and ‘month’ updated.
Here is my code:
import wixData from 'wix-data'
import wixUsers from 'wix-users-backend'
export function memberCollection_beforeInsert(item, context) {
//TODO: write your code here...
item.year = item.date.getUTCFullYear();
item.month = item.date.getUTCMonth() + 1;
wixUsers.getUser(item._owner)
.then((userInfo) => {
item.name = userInfo.memberName;
})
console.log(item)
return item;
}