0

Send Email Only Once

Hi Team,

See attached screenshot, I have a field called "contract renewal date" and a formula on the "contract renewal status" as per the below. How can I ensure the email only sends once? I was trying to update my "contract email sent" toggle field but appears I cannot update this from within the formula

let Date2 := 'Contract Renewal Date';
let Date1 := today();
let daysBetween := days(Date2, Date1) * -1;
if daysBetween = 90 then
    let userEmail := "david@platform81.com";
    sendEmail({
        from: "gary@platform81.com",
        to: userEmail,
        subject: "Thank you for your email",
        text: "We received your request to get another copy of your invoice",
        html: "Some text with markup"
    });
end;
if daysBetween <= 0 then
    styled("", "#cb2010", "")
else
    if daysBetween <= 90 then
        styled("", "#ffb452", "")
    else
        styled("", "#43d682", "")
    end
end

5 replies

null
    • John_Halls
    • 13 hrs ago
    • Reported - view

    Hi david

    Where is your code? Buttons and triggers will allow you to update fields but my guess is that it's in the Contract Renewal Status formula field. This will only run the last bit

    if daysBetween <= 0 then
        styled("", "#cb2010", "")
    else
        if daysBetween <= 90 then
            styled("", "#ffb452", "")
        else
            styled("", "#43d682", "")
        end
    end
    

    and ignore the rest.

    Regards John

      • david.6
      • 12 hrs ago
      • Reported - view

       yes you are correct, all of it is on the formula for Contract renewal status.

      Would I be best having like a button that could be triggered within the formula to send the email and update the checkbox?

    • John_Halls
    • 12 hrs ago
    • Reported - view

    Hi david

    Unfortunately a formula field can't trigger a button. You will need to press the button to execute its code. You could get the button to run the code for all your records, not just the record it's on.  There is also a Trigger after open, in the options of the app which would run every time you open the app.

    Let me know if you need a hand implementing it all.

    Regards John

      • david.6
      • 6 hrs ago
      • Reported - view

       appreciate the help. The trigger when the app opens sounds like it could be beneficial.

      From what I've sent so far, do you think there is any other solution that would work to ensure the email only sends once in my formula?

    • John_Halls
    • 5 hrs ago
    • Reported - view

    Hi david. There’s nothing in your code currently to prevent it sending ann email each time. I’ll post some code later tomorrow to show you how to put this right.