I have created a form in a list, and one of the fields required is a person/group field that I would like to send a notification email to when the form is submitted. I have a button at the bottom of the form and would like to assign a rule on the button to generate an email. I am having trouble finding the correct field to enter into the "to" section of the email.
2 Answers
The easiest way would be to create SharePoint Designer workflow which would run after the new item has been created. In it you can use Email
action and select the field which holds the person as the receiver of the email.
More on creating simple SharePoint designer workflows can be found here.
-
Is there a way to create a workflow to send the notification when a certain button is clicked? Right now I have a "save & Submit" "approve" and "deny" button that I would need the email notification for. So just having it for when the item is created would not suffice. Commented Feb 19, 2018 at 16:21
You can use this snippet on button click :
function processSendEmail() {
if ($("#empEmailId").val() != null) {
var userEmaiId = $("#empEmailId").val();
}
else {
alert("EmailId Should not be empty");
}
var From = '';
var To = userEmaiId;
var Body = 'You have been successfully submitted the data to List';
var SubjectOfEmail = 'Email Notification Using REST API';
sendEmailNotification(From, To, Body, SubjectOfEmail);
}
function sendEmailNotification(From, To, Body, SubjectOfEmail) {
hostWebUrl = decodeURIComponent(manageQueryStringParameter('SPHostUrl'));
var constructedURL = appWebUrl + "/_api/SP.Utilities.Utility.SendEmail";
$.ajax({
contentType: 'application/json',
url: constructedURL,
type: "POST",
data: JSON.stringify({
'properties': {
'__metadata': { 'type': 'SP.Utilities.EmailProperties' },
'From': From,
'To': { 'results': [To] },
'Body': Body,
'Subject': SubjectOfEmail
}
}
),
headers: {
"Accept": "application/json;odata=verbose",
"content-type": "application/json;odata=verbose",
"X-RequestDigest": $("#__REQUESTDIGEST").val()
},
success: function (data) {
alert('Email Sent Successfully');
},
error: function (err) {
alert('Error in sending Email: ' + JSON.stringify(err));
}
});
}