0

Automatic Calculating an end date based on new records

I'm quite new in Ninox and have a question on how to let Ninox calculate an end-date based on newly added records in a table

I have created a trigger whenever I change the status of a cow to add a record in a table which need to keep track of the status of the cow (Pregnant, Sick, etc).

I have now 3 columns: Date, Name Cow and New Status. All are takes from the action of changing the status of the cow in the Cow table.

Is there a way of adding a formula field as 'End Date' which can find the first earlier date of the same cow in that table and take this date as End date?

For example:

Date                  Name Cow      New Status          End Date

07-01-2024      Alisha               Pregnant              ?

07-22-2024      Alisha               Normal                  ?

 

I want to let the End date column to be populated now by '07-22-2024'.

If it cannot find a next date it can show 'N/A' or something and if it can find a next available date, I needs to show this date. 

Is there a way to accomplish this? Any help would be welcome.

2 Antworten

null
    • mirko3
    • vor 3 Monaten
    • Gemeldet - anzeigen

    Hi. Try this in formula field and change the name of table in code. Mirko

    let meCow := this.'Name Cow';
    let meDate := this.Date;
    let result := slice(((select Cows where 'Name Cow' = meCow and Date >= meDate) order by Date).Date, 0, 2);
    if last(result) = meDate then
        "N/A"
    else
        text(last(result))
    end
    
      • jesusfreakk_alex
      • vor 3 Monaten
      • Gemeldet - anzeigen

       Thanks for the help. I actually just figured it out. As 1 cow can only have 1 status at the same time, I just updated the date for the status field of the Cow which is not equal to the ID of the new created record.

      let newUpdate := (select 'Cow Status History')[newName = 'Name Cow' and 'Date Status End' = null and Id != newHistory.Id];
      newUpdate.('Date Status End' := now())

Content aside

  • Status Answered
  • vor 3 MonatenZuletzt aktiv
  • 2Antworten
  • 44Ansichten
  • 2 Folge bereits