Page 1 of 1

Sending Email on Row_Inserted / Row_Updated

Posted: Thu Nov 05, 2015 1:43 am
by ashworth81

Hi,

having migrated from ASPMaker I finding it quite difficult to transfer codes I used to use to the new format. BTW what is the code format used in the new server events? am I right in thinking VB.NET?

anyways in ASPMaker I used to use this code to send emails in the event of new row being added.

The code displayed a message to the user then sent an email based on conditions. It also retrieved the required recipients email from a table**.

Please can someone help me achieve this in asp.net. Just by helping me transfer the below code to the new format will help me learn massively as I will understand the new syntax a lot more.

' Row Inserted event
Sub Row_Inserted(rsold, rsnew)
IF visitor_log.Factory_Access.currentvalue = 1 OR visitor_log.Official_Factory_Tour.currentvalue = 1 THEN
Page.SuccessMessage = "Your Visitor(s): " & rsnew("visitor") & ", Requires Authorisation. The Authoriser has been informed."
End If
IF visitor_log.Official_Factory_Tour.currentvalue = 1 THEN
Dim Email1
Set Email1 = New cEmail
Email1.Content = "A New Visitor Has Been Requested, This Visitor Requires An Official Factory Tour. Please click the link To View The Request: hxxp://server/visitorsv1/Factory_Tour_Requestslist.asp"
Email1.Subject = "A New Visitor Requires An Official Factory Tour"
Email1.Sender = "email@email.com"
** Email1.Recipient = ew_executescalar("SELECT [Authorisers].[Official Factory Tours] FROM [Authorisers] WHERE [Authorisers].[ID] = 1;") **
Email1.Send()
End If
IF visitor_log.Official_Factory_Tour.currentvalue = 1 THEN
Dim Email9
Set Email9 = New cEmail
Email9.Content = "A New Visitor Has Been Requested, This Visitor Requires An Official Factory Tour. Please click the link To View The Request: hxxp://server/visitorsv1/Factory_Tour_Requestslist.asp"
Email9.Subject = "A New Visitor Requires An Official Factory Tour"
Email9.Sender = "email@email.com"
Email9.Recipient = ew_executescalar("SELECT [Authorisers].[Official Factory Tours] FROM [Authorisers] WHERE [Authorisers].[ID] = 2;")
Email9.Send()
End If

Any help is greatly appreciated.


Re: Sending Email on Row_Inserted / Row_Updated

Posted: Thu Nov 05, 2015 1:48 pm
by motfs

You can use ew_EmailSend() function to send email. Check out the function in aspxfn12.cs.

If you encounter error in your code, post the error message.


Re: Sending Email on Row_Inserted / Row_Updated

Posted: Thu Nov 05, 2015 6:12 pm
by ashworth81

Hi,

When the row was added the email did not send. Is it possible to send email from the Row_inserted / Row_updated event?

Can anyone spot an issue in the below code?

// Email Sending event
public bool Email_Sending(ref cEmail Email, dynamic Args) {
if (CurrentPageID() == "add") { // If Add page
Email.Recipient = "me@email.com"; // Change recipient to a field value in the new record
Email.Subject = "My New Subject"; // Change subject
Email.Content = "test"; // Append additional content
}
return true;
}


Re: Sending Email on Row_Inserted / Row_Updated

Posted: Fri Nov 06, 2015 11:48 am
by motfs

This is C# code. But do you want to write VB?

Do you enable the Email Notification on Add? Clarify the setup and the code you have. And make sure you have setup "Email Settings" correctly.

Or use my suggestion to send email by ew_EmailSend() function.


Re: Sending Email on Row_Inserted / Row_Updated

Posted: Thu Jan 28, 2016 6:19 pm
by ashworth81

Hi,

I would like to send an email when a row has been updated, or maybe deleted ect..

have been trawling through the support forum, I the server events do I type the code in Razor format?

have tried this with no joy.

// Row Updated event
public void Row_Updated(OrderedDictionary rsold, OrderedDictionary rsnew) {
// ew_Write("Row Updated");

Dim sSender As String, sRecipient As String, sCc As String, sBcc As String, sSubject As String, sContent As String, sFormat As String, sCharset As String;

sSender = "mail@mail.com"
sRecipient = "mail@mail.com"
sCc = ""
sBcc = "mail@mail.com"
sSubject = "test"
sContent = "test"
sFormat = "html"
sCharset = "utf-8"
ew_SendEmail(sSender, sRecipient, sCc, sBcc, sSubject, sContent, sFormat, sCharset)

}


Re: Sending Email on Row_Inserted / Row_Updated

Posted: Fri Jan 29, 2016 9:34 am
by Webmaster

You need to use C# codes. Read the Email_Sending example in help file topic: Server Events and Client Scripts.