How to write afterinsert function in wix database

hi everyone, i'm building a website on wix and i have a problem that i can't solve.
i have a database collection in my website called royaldynasty and i want that after a user is submiting my website, a function(afterInsert) will combine some of the fileds text into another.
i have allready read the examples in wix how to do so.
but it's still dont work.
my database collection name is royaldynasty, the fields that i want to take data from are Called(fieldkey):kingsName,countrys,citys.
the field that i want to fut the new data is called(fieldkey):upperTitle.
i want that after a user submit my website(the data enters the database) the function(afterInsert) will insert <the richest king in the world is kingsName from citys, countrys.> into tha filled upperTitle
so i saw this explantion on wix https://www.wix.com/code/reference/wix-data.Hooks.html#afterInsert
i tryed to write the code like they explaind but that doesent work in the website. thats the code i I have written enter image description here.
i wil love if someone will show me how to write the code right and give explanation so in the future i can write data hooks on wix by myself.
i dont know coding very good so the explanation should be spesific and simple. Thanks from advance, and sorry for the bad english:)

This doesn't look like a Transact SQL question.