Help with Creating First Record in Empty Table via Button in Ninox
Hello Community,
I'm currently working with Ninox and trying to set up a button that will create the first record in a table. My table, named "New Months Report"
, is initially empty, and I need the button to handle this situation by creating the first record with default values when the table is empty.
Here’s the logic I’m trying to implement:
- Check if the table is empty — If the table is empty, I want to create a new record.
- Create the first record — If the table is empty, the first record should be created with the current date as the 'Beg Date' and 'End Date' as 30 days after today.
Here’s the formula I have so far:
let oldData := select 'New Months Report';
if count(oldData) = 0 then
let newRec := create('New Months Report');
newRec.'Beg Date' := today(); // Set Beg Date to today's date
newRec.'End Date' := today() + 30; // Set End Date to 30 days after today
else
// If there are records, duplicate the last record
let lastRecord := last(oldData order by 'Beg Date');
let newRec := duplicate(lastRecord);
newRec.'Beg Date' := today();
newRec.'End Date' := today() + 30;
end;
However, I'm encountering an issue where, when the table is empty, the formula doesn’t seem to be creating a new record (does not see the table 'New Months Report'). Could anyone point out if there’s a mistake in the formula or if there's a different approach for handling this?
Any guidance would be greatly appreciated!
Thank you!
16 replies
-
This works for me:
let oldData := (select 'New Months Report'); if count(oldData) = 0 then let newRec := (create 'New Months Report'); newRec.('Beg Date' := today()); newRec.('End Date' := today() + 30) else let lastRecord := last(oldData order by 'Beg Date'); let newRec := duplicate(lastRecord); newRec.('Beg Date' := today()); newRec.('End Date' := today() + 30) end
When I pasted your code, it gave an error on line 3. You had the parentheses in the wrong place.
-
said:
table New Monts report is a subtable in a table EMPLOYEESSo the reference field is called New Months Report, but that is not the actual table name. Can you post a screenshot of the Edit Field screen so we can see the relationship? This will show you the actual table name.
Content aside
- 2 wk agoLast active
- 16Replies
- 79Views
-
2
Following