I'm trying to send an automatic email receipt for items that have been created on a sharepoint list.
Conditions
- I cannot use workflows - they are disabled
- I cannot use webparts - they are disabled
- I cannot use sharepoint designer etc etc etc - they are all disabled
- The function needs to be OOTB
The only option I have is using javascript in calculated columns. I am aware of the use of the HTML:mailto tag - but this opens Microsoft outlook, and is not automatic.
Came across this link:
So, here is the calculated column attempt:
="<button onclick=""{function SendEMail(from, to, body, subject){"
&"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': $('#__REQUESTDIGEST').val()"
&"},success: function (data) {"
&"alert('Eposten ble sendt');"
&"},error: function (err) {"
&" alert(err.responseText);"
&" debugger;}});}"
&"SendEMail('user@whatever.com','user@whatever.com','Test1','Test2');}"">"&"Send</button>"
When running the code, the Console shows the following error: '$' is undefined
Any suggestions on how to overcome this?
Thanks