How to copy fields on create
I have two tables: Clients & Offers.
Whenever I create a new client, I also want to create a new offer and copy some fields from the Clients entry, like First Name.
So I have the following code triggered on a new record.
let currentCustomer := this;
let newOffer := (create Offers);
newOffer.(Cost := 5555);
newOffer.('Full Customer Name' := currentCustomer.'First Name');
newOffer.(Client := currentCustomer);
The offer gets created, but the field 'Full Customer Name'.
If I use the same code with trigger after update, it works.
Questions:
1. It seems that this
does not contain the data I need. Am I missing anything?
2. Is there a debugging console where I can run something like console.log(this) ?
Thanks for any help or hints.
5 replies
-
Looks like you have answered your question. If the code in Trigger on New Record, you have not entered in any data for Ninox to copy. Try putting the code in Trigger after Update under the 'First Name' field.
-
Thanks for the answer, Fred.
I was interested in "Trigger on New Record" as this ensures that other records are created only once since the trigger is called only once.
What is confusing is that the relationship is created, sonewOffer.(Client := currentCustomer);
works.
I would really like to debug this with something like console.log(). Any ideas? -
There is a console but I've never used it so I can't give any help there.
That said, when you create a new record in Client, a record Id is created, so that relationship can be linked. So your code is working. When you create a new record in Client you don't have a First Name yet so Ninox has nothing to copy to the new record in the Offers table.
If you want to be sure not the create duplicate offers then you can add an if statement to your code. Something like:
let currentCustomer := this;
let checkDup := cnt(select Offers ['Full Customer Name' = currentCustomer.'First Name'])<--counts the number of records from the Offers table where 'Full Customer Name' = 'First Name'
if checkDup = 0 then<--if the count equals 0 (meaning it didn't find any records where Full Customer Name' = 'First Name') then it goes ahead and creates the record. otherwise it will do nothing.
place create code here
end
Good luck and let us know how it goes.
-
Ok, that makes sense. Thanks for clarifying the way things work.
Seems to be working as you have explained it. :)
-
Find your new Italian driver’s license with The Real Italian.
Italian driver’s license: Driving in Italy is much more than just a way to get to work or make sure you can make it to the supermarket, it’s also an integral part of the culture. So if you want to live in Italy and drive, you’ll need an Italian driver’s license. Not only does our service provide you with your new Italian driving license, but we also help you convert your international driver’s license into one that will allow you to drive in Italy over the course of your first year as a resident in Italy.
An Italian driver’s license is one of the most important documents you’ll need to have when driving in Italy. In this article, we’ll break down your options on how to get a license and what it takes to get behind the wheel.The Real Driver’s License is a complete set of Italian driving documents.
This includes your Italian driving license, International Driver’s License, driver’s manual, and an official translation of your driver’s license from your home country.
Buy an Italian driving license: If you want to live in Italy and drive, you’ll need an Italian driver’s license. If you’re lucky and you already have a license issued by the EU or one of the countries on this list, you can simply convert your license to an Italian one. However, if you’re not from one of the eligible countries like if you’re like me and have a license from the USA, during your first year as a resident in Italy, you’ll be able to drive with your license and International Driver’s License, but once that year is up, you’ll have to go to driving school and take the permit and driver’s exam in.However, if you’re not from one of the eligible countries like if you’re like me and have a license from the USA, during your first year as a resident in Italy, you’ll be able to drive with your license and International Driver’s License, but once that year is up, you’ll have to go to driving school and take the permit and driving exams.
Content aside
- 3 yrs agoLast active
- 5Replies
- 226Views