Can we create workflows through HTML / JavaScript or it can only be done through SharePoint Designer.
ViqarBeginner
Can we create workflow for sending emails through HTML / JavaScript or it can only be through SharePoint Designer.
Share
adeelaslam
Web Script Editor adds HTML and JavaScript capabilities.
SPBuddy
I will not say we cannot achieve workflow actions kind of behavior using JavaScript/HTML but there will be alot of limitations when we say a workflow actions. Because both HTML and JavaScript are running on client side.
If you are asking just about email functionality yes that can be done using JavaScript APIs.
Abdullah Khan
Yes, We can send email through HTML/JavaScript using SPUtility Send Email.
Pease find below sample code.
function processSendEmails() {
var from = ‘asad@Example.com’,
to = ‘someone@Example.com’,
body = ‘Hello World Body’,
subject = ‘Hello World Subject’;
// Call sendEmail function
//
sendEmail(from, to, body, subject);
}
function sendEmail(from, to, body, subject) {
//Get the relative url of the site
var siteurl = _spPageContextInfo.webServerRelativeUrl;
var urlTemplate = siteurl + “/_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”: jQuery(“#__REQUESTDIGEST”).val()
},
success: function(data) {
alert(‘Email Sent Successfully’);
},
error: function(err) {
alert(‘Error in sending Email: ‘ + JSON.stringify(err));
}
});
}
$(document).ready(function () {
SP.SOD.executeFunc(‘sp.js’, ‘SP.ClientContext’, processSendEmails);
});