0

Is it possible to send an email in PreSaveAction function using JavaScript?

I tried this example. But it is not working.

Or is there a way to include the Email address provided in the NewForm to be added in the Workflow SendEmail?

UPDATE

I'm using SharePoint 2013 Online. And below is the code:

function sendEmail(from, to, body, subject) {
appweburl = decodeURIComponent(getQueryStringParameter('https://url'));
alert(appweburl);
hostweburl = decodeURIComponent(getQueryStringParameter('https://url/'));
var urlTemplate = appweburl + "/_api/SP.Utilities.Utility.SendEmail";
$.ajax({
    contentType: 'application/json',
    url: urlTemplate,
    type: "POST",
    data: JSON.stringify({
        'properties': {
            '__metadata': { 'type': 'SP.Utilities.EmailProperties' },
            'From': from,
            'To': { 'results': [to] },
            'Body': body,
            'Subject': subject
        }
    }
  ),
    headers: {
        "Accept": "application/json;odata=verbose",
        "content-type": "application/json;odata=verbose",
        "X-RequestDigest": $("#__REQUESTDIGEST").val()
    },
    success: function (data) {
       console.log('success')
    },
    error: function (err) {
        console.log(JSON.stringify(err));
    }
});
}
Keerthi
  • 1,113
  • 2
  • 15
  • 32

1 Answers1

1

In your custom list you can add a field to capture Email. Then inside the workflow you can sent email to CurrentItem:Email

Amal Hashim
  • 28,306
  • 5
  • 31
  • 61