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));
    }
});
}
1
  • Is email configured properly on your server? Can you post the code you tried so far? Commented Apr 10, 2015 at 16:51

1 Answer 1

1

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

7
  • I'm getting the Email from the People picker field under the PreSaveAction function. How to add it to the list? Commented Apr 10, 2015 at 16:59
  • I am confused. Isn't the field available in the new form? Commented Apr 10, 2015 at 17:00
  • The new form has a people picker field. From which I am getting the Email address under the PreSaveAction function. There is no actual field for Email address. Commented Apr 10, 2015 at 17:02
  • 1
    Ok then why can't you add a new field for selecting people? Then in the workflow Sent Email to CurrentItem:UserField - Choose to return email Commented Apr 10, 2015 at 17:05
  • Super cool. I didn't know it was this simple. Commented Apr 10, 2015 at 17:24

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.