This topic is locked
[SOLVED]

Help with Code To Compare Values of a field before sending e-mail

5/25/2021 5:58:36 PM
ASPRunner.NET General questions
D
DebZ author

Hello,

If someone would help me with a bit of custom code to help me it would be appreciated. I have the code to send an e-mail and it works fine. (Take from the examples in the manual).

Now I would like to only send this e-mail under the following conditions.

  1. When its a new record if the value of a particular field (Lets call this field "ProjectStatus") is a specific value. (Example only when project status = "ABCDEF"
  2. When its an existing record being edited and the value is being changed to the value "ABCDEF" from another value.

I relaize there are two event places for this (After Update, and After Edit Change) but I'm not sure how to properly test the value of the field. (syntax too)
I thought I would compare the values("ProjectStatus") with my text critera. such as

On the newly added records after update event.

If values("ProjectStauts")="ABCDEF" {
e-mail code
}

But I must be typing something wrong.

And on the Edit Record After Update event, how do I compare the old value of the field to make sure it wasn't "ABCDEF" and the new value in the field to make sure it IS "ABCDEF" before sending the e-mail?

Thanks,

Fam

Pete K 5/25/2021

Try this:

If (values["ProjectStauts"].ToString() == "ABCDEF") {
e-mail code
}
Pete K 5/25/2021

And for the second one:

if ( oldvalues["ProjectStauts"].ToString() != "ABCDEF" && values["ProjectStauts"].ToString() == "ABCDEF")
{
code
}

D
DebZ author 5/25/2021

Thank you for both of those, I will try them tomorrow when I can kick folks out of the system. :)

Very much appreciated.

Fam

D
DebZ author 5/27/2021

It didn't work but I know you must be close.
My e-mail code (taken from example in manual) works fine.

XVar retbb = MVCFunctions.runner_mail(new XVar("to", emailbb, "subject", subjectbb, "body", msg.ToString(), "from", from));
if(!retbb["mailed"])
{
MVCFunctions.EchoToOutput(retbb["message"]);
}

But, when I wrap the check for the status condition, it will not compile. The error is that a ; is expected. Which makes no sense as the If command should not require one right?

Here is the code that wont compile. (All the variables are declared elsewhere and like I said the e-mail settings above work fine without the If statement on the check.)

If (values["Status"].ToString() == "Awarded")
{
XVar retbb = MVCFunctions.runner_mail(new XVar("to", emailbb, "subject", subjectbb, "body", msg.ToString(), "from", from));
if(!retbb["mailed"])
{
MVCFunctions.EchoToOutput(retbb["message"]);
}
}
admin 5/27/2021

Show us the complete code of this event and also the complete error message. This code alone looks correct.

Also instead of "If" use "if"

D
DebZ author 6/9/2021

Sorry this took so long to get back to. I wasn't able to work on this project until today.
Changing the Capital "I" to lower case "i" for the if statement was the issue. (Feel like an idiot.)

Thank you so much!