1

I have a sharepoint list with 3 columns. User edits the item and updates a column. CLicks on custom button present on the ribbon for send email. The email body should contain the value of 3 columns (updated one) and also outlook client should open. I tried using mailto but, i am not able to add the item data to the body.

Is there any other approcah That i can try.

Edit: Here is the code I have written in script.js file

var itemID = "";
var listItemInfo = '';
var targetListItem;
function mailThisPage(olist) {
ExecuteOrDelayUntilScriptLoaded(getListData, "sp.js");
var mailTo = encodeURIComponent(listItemInfo) + encodeURIComponent('The following item has been updated:');
window.location = "mailto:deepika-tyagi@abc.com?Subject=Item Information&body=" + mailTo;
}
function getListData() {
var clientContext = SP.ClientContext.get_current();
var myList = clientContext.get_web().get_lists().getByTitle('CMCalendar');
var itemId = _spGetQueryParam('id');

targetListItem = myList.getItemById(itemId);
clientContext.load(targetListItem, 'OrderSummary');
clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed));
}

function onQuerySucceeded(sender, args) {
alert('Request succeeded. \n\nRetrieved Item is: ' + targetListItem.get_item('OrderSummary'));
debugger;
listItemInfo = targetListItem.get_item('OrderSummary');
}

function onQueryFailed(sender, args) {
alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
}
  • added the code block – Deepika Mar 4 '15 at 13:56
1

Move the code that opens the mail client to success method. As JavaScript client object model runs asynchronously it doesn't wait for success method to complete. Hence the variable whose value is assigned in the success method is empty when calling mailto.

function onQuerySucceeded(sender, args) {
alert('Request succeeded. \n\nRetrieved Item is: ' + targetListItem.get_item('OrderSummary'));
debugger;
listItemInfo = targetListItem.get_item('OrderSummary');
var mailTo = encodeURIComponent(listItemInfo) + encodeURIComponent('The following item has been updated:');
window.location = "mailto:deepika-tyagi@abc.com?Subject=Item Information&body=" + mailTo;
}

Noe that I haven't tested your code.

1

You can write workflow/ event receiver on item updating calendar list to send email.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.