Creating Table Records

By Jennifer Neighbors, Senior Consultant


Whether or not you have administrative rights, it’s easy to insert new records into your database tables. Click the “+” after the last record in a table when you are in table view or click the plus symbol inside of the circle in the upper right corner of the screen in either table or form view. A new, blank form will open for you to use to enter your new record. However, if you have administrative rights, and you are writing code in your database, you may want to make a new table record using code. The simplest and most common situation I encounter is when I want to add a NEW button to a form to let the user simply press that button to add a new record. A big, bold, colorful button is easier for users to see and understand than Ninox’s small plus symbol inside a circle and it provides you the opportunity to add some values to the resulting record as well. Create a button, and, in the button’s “on click” function, enter code like this:

					let x := (create INVOICES);

This code creates a new record in the Invoices table and then opens that record for the user to see and edit. Remember I said I could also add a field value to my new record? Using the variable as a reference to the new record, I can enter the value I want the new record to have. Then my code would look something like this:

					let x := (create INVOICES);
x.('Invoice Date' := today());

The next method I’ll demonstrate is takes things further using this same method. I use it when I’m writing code to execute a longer function that includes creating some records. First, I pick a simple variable and use it with the Create Record function. Then I define each field value in my new record using the variable as a reference like this:

					let i := (create Customer);
i.( 'Customer First Name' := “Alicia”);
i.('Customer Last Name' := “Smith”);
i.('Sales Territory' := 5);
i.('Sales Rep' := “Sam Strong)” 
…more code
(Invoice.Customer := i);
…more code				

Notice that, not only have a created a new table record, but also I have referred back to that new record later on in my code when I need to do so. If you are like me, you’ll be writing longer and longer blocks of code as you gain experience and programming ambition. However, with really long code blocks, you will eventually either run out of letters to use as variables or you will start to forget which ones you’ve already used (and you do not want to reuse these variables in the same code block). When this has happened a few times, try this variant of the code above:

					let xCustomer := 0;
(create Customer).( 
    'Customer First Name' := “Alicia”;
    'Customer Last Name' := “Smith”; 
    'Sales Territory' := 5; 
    'Sales Rep' := “Sam Strong”;
    xCustomer := number(Id)
… more code
Invoice.Customer := xCustomer
… more code				

This style of creating records discards the variable while allowing you to accomplish the same thing. Once again, I have referred back to the new record later in my code, but this time I did it a little differently. If you are relatively new to creating records using Ninox coding, I hope this introduction will help you get started. Once you try these methods a few times, I am sure you’ll agree that it’s easy to do!


Jennifer welcomes feedback and can be reached at