0

New Record with prefilled date field

What would be the code to put in "on Create" so that when the new record is created, the Date field is automatically completed with the next date of the previous.

Example.

one record is set on the 1st January. I press a button which creates a new record. The new record will automatically have the 2nd January 

is this possilbe?

10 replies

null
    • Ninox partner
    • RoSoft_Steven.1
    • 2 yrs ago
    • Reported - view
    let d := last((select YourTable).Date);
    Date := if d then d + 1 else today() end

    Steven

      • Admin.11
      • 2 yrs ago
      • Reported - view

      RoSoft_Steven Rooryck 

      So i thought my problem was solved.

      new problem has arisen.

      So i originally had it so when the date field was completed, it auto filled the appointment fields with a preset time for that particular date.

      When i use your code to create a new record with a prefilled date field. It does it does not create create the new appointments after update. 

      I then thought to move my code to "trigger on new record" to complete the appointment dates. It is working, but the complete wrong times are being used.

      let d := last((select 'Snorkel / Sea Scooter Bookings').Date);
      Date := if d then d + 1 else today() end;
      (
          let dS := Date + time(10, 0);
          let dF := Date + time(11, 30);
          '10 am' := appointment(dS, dF)
      ) + (
          let dS := Date + time(13, 0);
          let dF := Date + time(14, 30);
          '1 pm' := appointment(dS, dF)
      ) + (
          let dS := Date + time(15, 15);
          let dF := Date + time(16, 45);
          '3:15 pm' := appointment(dS, dF)
      )

       

      The appointment times are coming out as 7:00 pm to 8:30pm for the first one and not 10:00am and 11:30 am.

      any suggestions?

      • Ninox partner
      • RoSoft_Steven.1
      • 2 yrs ago
      • Reported - view

      Admin Try this:

      let d := last((select 'Snorkel / Sea Scooter Bookings').Date);
      Date := if d then d + 1 else today() end;
      let dS := datetime(date(Date),time(10, 0));
      let dF := datetime(date(Date),time(11, 30));
      '10 am' := appointment(dS, dF);
      let dS := datetime(date(Date),time(13, 0));
      let dF := datetime(date(Date),time(14, 30));
      '1 pm' := appointment(dS, dF);
      let dS := datetime(date(Date),time(15, 15));
      let dF := datetime(date(Date),time(16, 45));
      '3:15 pm' := appointment(dS, dF)
      
      

      Steven

      • Admin.11
      • 2 yrs ago
      • Reported - view

      RoSoft_Steven Rooryck Thank you for the quick response.

      I have placed your code in "trigger on new record" and it is creating the new record with the correct date, but not completing the appointment dates. 

      Have i placed the code in the correct area. I am still using a button to create the new records

      • Ninox partner
      • RoSoft_Steven.1
      • 2 yrs ago
      • Reported - view

      Hello, Admin 

      1) You can use the above code in the "Trigger on new record" setting in the table.

      2) If you want to use a button to create new record, then use this code: (no more code in the "trigger on new record" needed then)

      let d := max((select 'Snorkel / Sea Scooter Bookings').Date);
      let i := (create 'Snorkel / Sea Scooter Bookings');
      i.(
          Date := if d then d + 1 else today() end;
          '10 am' := appointment(datetime(date(i.Date), time(10, 0)), datetime(date(i.Date), time(11, 30)));
          '1 pm' := appointment(datetime(date(i.Date), time(13, 0)), datetime(date(i.Date), time(14, 30)));
          '3:15 pm' := appointment(datetime(date(i.Date), time(15, 15)), datetime(date(i.Date), time(16, 45)))
      );
      openRecord(i)
      

      I prefer the use of max() function because this is more reliable. (Also in the code for the trigger posted above where i used the last()function, It should have been max())

      If you're using the "Trigger on new record" method (which is faster executed) and still want to use a button to create a new record then place only this code in the button:

      let i := (create 'Snorkel / Sea Scooter Bookings');
      openRecord(i)
      

      Steven

      • Admin.11
      • 2 yrs ago
      • Reported - view

      RoSoft_Steven Rooryck 

      Thankyou for all your help. I still quite couldnt get the appointments to display the correct times. Ive got the system working with a slight glitch.

      Ive got:

      This code in the "trigger on new record"

      let d := last((select 'Snorkel / Sea Scooter Bookings').Date);
      Date := if d then d + 1 else today() end;
      (
          let dS := Date + time(10, 0);
          let dF := Date + time(11, 30);
          '10 am' := appointment(dS, dF)
      ) + (
          let dS := Date + time(13, 0);
          let dF := Date + time(14, 30);
          '1 pm' := appointment(dS, dF)
      ) + (
          let dS := Date + time(15, 15);
          let dF := Date + time(16, 45);
          '3:15 pm' := appointment(dS, dF)
      )

      I then use the this code (Same as above) in "trigger after update" in the date field

      (
          let dS := Date + time(10, 0);
          let dF := Date + time(11, 30);
          '10 am' := appointment(dS, dF)
      ) + (
          let dS := Date + time(13, 0);
          let dF := Date + time(14, 30);
          '1 pm' := appointment(dS, dF)
      ) + (
          let dS := Date + time(15, 15);
          let dF := Date + time(16, 45);
          '3:15 pm' := appointment(dS, dF)
      )

       

      Followed by a button  that creates a new record

      let newRec := (create 'Snorkel / Sea Scooter Bookings');
      openRecord(newRec).

       

      From all this coding, once the very first appointment has been created, the button then works perfectly for all future appointment. It only gives weird appointment times on the very first record.

    • Admin.11
    • 2 yrs ago
    • Reported - view

    Thanks for the reply Steven.

    Just double checking.

    Ive inputted the code into my table and no errors are coming up, but nothing seems to have changed.

    Ive put the code in my button and ive got it so on click. It creates and opens a new record. But the date field still stays empty.

    the code on the button is :

    let newRec := (create 'Sight See Fish Feed / Marine Discovery Cruise Booking Sheet');
    openRecord(newRec);

    let d := last((select 'Sight See Fish Feed / Marine Discovery Cruise Booking Sheet').Date);
    Date := if d then d + 1 else today() end

    Is this correct or should i have the code in another field?

    thankyou very much for your help

      • Ninox partner
      • RoSoft_Steven.1
      • 2 yrs ago
      • Reported - view

      Admin The code I placed is to be used in the "Trigger on new record" of the table setting.

      If you want to use it in a button, then try this:

      let d := max((select 'Sight See Fish Feed / Marine Discovery Cruise Booking Sheet').Date);
      let newdate := if d then d + 1 else today() end;
      let newRec := (create 'Sight See Fish Feed / Marine Discovery Cruise Booking Sheet');
      newRec.(Date := newdate);
      openRecord(newRec);
      

      note : I've also changed last( ) to max() in my script because last check's the last created record and this isn't always the record with the highest date.

      Steven

    • Admin.11
    • 2 yrs ago
    • Reported - view

    Thank you steven for the clear up.

    Ive inputed your code, and it seems to be working. However, it is creating every alternate day. As in its the i created a record for the 19th, i click the button and it creates the next record with the 20th which is great. I then click the button on the new record and it creates a new record with the 22nd as the date.

    • Admin.11
    • 2 yrs ago
    • Reported - view

    Ignore last reply, Ive inputted your original code into the trigger on new record and it works and treat.

    Thankyou very much for your assisstants

Content aside

  • 2 yrs agoLast active
  • 10Replies
  • 219Views
  • 2 Following