How to auto create new record every day?
I have to create a daily record, but I have to hit the button every time. Now I want to use loop function to create new record every day. can someone show me how please?
29 replies
-
There isn't a way to run a script based on time.
You can do the create() command when you open the DB, Trigger on open. You can add code that will check if a record for the day already exist and only create a record if there is not a record for the day.
-
Try creating a button on the Home table with:
create 'THU/CHI'
Now if we add this to the Trigger on open for the DB then it will create a record everytime you open DB and that is not good. So we need to add some logic.
You can then modify the button code to:
let anyOldRecs := select 'THU/CHI' where NGAY = today(); if count(anyOldRecs) < 1 then create 'THU/CHI' end
So if you try it out, it shouldn't create a record since you already did for today. If you delete the record with today's date then click the button it should work.
If all this works then copy the code to the Trigger after open for the your DB.
-
@Fred there is something wrong with this formular. It keep create 2 record, and I have to delete, when it happen every time.
please help me.
let anyOldRecs := select 'THU/CHI' where NGAY = today(); if count(anyOldRecs) < 1 then create 'THU/CHI' end
-
Everytime I trigger it, some time it create 1 record and I try to trigger it many times it is not create another one. But some time, it create another one. I don't know what happen with it.
-
said:
Everytime I trigger it, some time it create 1 record and I try to trigger it many times it is not create another one. But some time, it create another one. I don't know what happen with it.said:
there is something wrong with this formular. It keep create 2 record, and I have to delete, when it happen every time.So which one is it?
next to your button create a new formula field and put this in it:
let anyOldRecs := select 'THU/CHI' where NGAY = today(); concat(anyOldRecs)
Before you press the button see if you see any records in the field. It should only create a record if there are no records found.
-
I tried to do this but it keep Create 2 record. I am so confusing now, because it work well from the morning, and then when it come to 4:00 PM at the afternoon, it create another record. Please help me I don't know what to do now. I tried to test so many time but it didn't workout. I am so desparated.
let anyOldRecs := select 'THU/CHI' where NGAY = today(); if count(anyOldRecs) < 1 then create 'THU/CHI' end
-
said:
Thanks, I'm going to try it after 4pm PST as I am also in PST.Well I was able to duplicate the issue. I thought they fixed date issues like this when they made DBs Timezone independent. What an annoying "feature".
Did Ninox say there was no way to make this work?
Playing around I was able to get it find the "correct" records by stripping out the year, month, and day out of the today() command, turn them into numbers, then use the date() command to put it back together.
It looks something like this;
let xyear := number(year(today())); let xmonth := number(month(today())); let xday := number(day(today())); let anyOldRecs := select 'THU/CHI' where NGAY = date(xyear,xmonth,xday); if count(anyOldRecs) < 1 then create 'THU/CHI' end
This is where used the extra formula field I suggested earlier comes in handy. Originally, I put this in the code box:
debugValueInfo(select Table1 where Date = today())
And it would show me:
nid([])
which means it found no records matching even though there was one.
Then I played around and settled on this:
let t := this; let xyear := number(year(today())); let xmonth := number(month(today())); let xday := number(day(today())); debugValueInfo(select Table1 where Date = date(xyear, xmonth, xday))
and I got back:
nid([A21])
So now I know it found something and now if I transfer the new code to the button then the if statement will work.
Content aside
- Status Answered
- 7 mths agoLast active
- 29Replies
- 189Views
-
3
Following