1

How to pop up a dialog if a record in a table meets a criteria.

I have a table with three records each with a specific date in a field called next date. I am trying to use the trigger after open function to allow a dialog to pop up when the date in the next date field of any record is today. At the moment the dialog is popping up regardless of the date. How do I fix this?

here's my code:

let z := (select 'Reminders' where 'Next Date' = today());
let i := join(z.Reminder, "
");
if z !=null then
    let result := dialog("A reminder is due today. Do you want an email detailing what needs to be done?", i, ["Yes", "No"]);
    if result = "Yes" then
        alert("You pressed Yes and an email will be sent");
        sendEmail({
            from: "m",
            to: ".com",
            cc: "",
            subject: "Test lab reminder",
            text: "This is a test reminder."
        })
    else
        if result = "No" then
            alert("You pressed no and an email will not be sent")
        end
    end
else
    alert("Space")
end

7 replies

null
    • Ninox partner
    • RoSoft_Steven.1
    • 8 mths ago
    • Reported - view

    Change the first 4 lines code in and see if this works:

    if cnt(select Reminders where 'Next Date' = today()) > 0 then

    • IFD_Engineering
    • 8 mths ago
    • Reported - view

    That should work, but when I add count it tells me I have an error on lines 2 and 3. 

      • Ninox partner
      • RoSoft_Steven.1
      • 8 mths ago
      • Reported - view

      IFD Engineering 

      Sorry for the confusion, this is the whole code (I think that should work):

      if cnt(select Reminders where 'Next Date' = today()) > 0 then
          let result := dialog("A reminder is due today. Do you want an email detailing what needs to be done?", i, ["Yes", "No"]);
          if result = "Yes" then
              alert("You pressed Yes and an email will be sent");
              sendEmail({
                  from: "m",
                  to: ".com",
                  cc: "",
                  subject: "Test lab reminder",
                  text: "This is a test reminder."
              })
          else
              if result = "No" then
                  alert("You pressed no and an email will not be sent")
              end
          end
      else
          alert("Space")
      end
      • Fred
      • 8 mths ago
      • Reported - view

       

      Background on why you are getting the error message.

      When you changed line 1 to a count, variable z is now a simple number when it use store NID data. So that breaks the code in variable i in line 2 that was dependent on z containing table data.

    • IFD_Engineering
    • 8 mths ago
    • Reported - view

    Now however, i is not defined.

    • John_Halls
    • 8 mths ago
    • Reported - view

    Try this

    let z := (select 'Reminders' where 'Next Date' = today());
    if cnt(z) > 0 then
        let i := join(z.Reminder, "
        ");
        let result := dialog("A reminder is due today. Do you want an email detailing what needs to be done?", i, ["Yes", "No"]);
        if result = "Yes" then
            alert("You pressed Yes and an email will be sent");
            sendEmail({
                from: "m",
                to: ".com",
                cc: "",
                subject: "Test lab reminder",
                text: "This is a test reminder."
            })
        else
            alert("You pressed no and an email will not be sent")
        end
    else
        alert("Space")
    end
      • IFD_Engineering
      • 8 mths ago
      • Reported - view

       Thank you, this worked!

Content aside

  • 1 Likes
  • 8 mths agoLast active
  • 7Replies
  • 128Views
  • 5 Following