Applies to the Calendar E-Mail Extension for SharePoint on-premises (SE, SP2019, SP2016, …)
How to: Send an invitation to the creator of an event using Calendar E-mail Extension
A few of your customers recently asked if it’s possible to send an invitation to the creator of an event automatically using the Calendar E-mail Extension. The answer is yes, but the creator has to be added to the ‘Attendees’ column.
The Calendar E-Mail Extension was one of the first SharePoint add-ins we published following Event Management for SharePoint 2010, later for SharePoint 2013, 2016 and finally SharePoint 2019 and SE. The app is still a great success and though the majority has moved over to Event Management, Employee Training Management or Calendar E-Mail Extension on SharePoint online, there are still many customers using it in SharePoint on-premises environments.
Since it’s not possible to set a default value for a user column (people picker), we have to do it using JavaScript.
Here is the entire script:
ExecuteOrDelayUntilScriptLoaded(init_setDefaultUser,\'sp.js\'); var currentUser; var currentUserLoginName; var currentUserTitle; function init_setDefaultUser(){ //get the current user var clientContext = new SP.ClientContext.get_current(); var oWeb = clientContext.get_web(); currentUser = oWeb.get_currentUser(); clientContext.load(currentUser); clientContext.executeQueryAsync(onQuerySucceededCurrentUser, onQueryFailedCurrentUser); } function onQueryFailedCurrentUser(sender, args) { } function onQuerySucceededCurrentUser() { //get login name and display name of the current user currentUserLoginName = currentUser.get_loginName(); currentUserTitle = currentUser.get_title(); //call fillDefaultUser fillDefaultUser(); } function fillDefaultUser() { //fill the second people picker fillPeoplePickerWithCurrentUser(2); } function fillPeoplePickerWithCurrentUser(pickerNo) { if(currentUser != null) { //get the people picker with the given number var pp = getPickerImputElement(pickerNo); if(pp != null) { //build entities xml var key = currentUserLoginName; var dispval = currentUserTitle; var xml = \'\'; xml = xml + \'\' xml = xml + \'\'; //call EntityEditorCallback EntityEditorCallback(xml, pp.id, true); } } } function getPickerImputElement(pickerNo) { var result = \'\'; //get all people picker controls var pp = document.getElementsByClassName(\'ms-usereditor\'); var j = 0; for(var i=0; i < pp.length; i++) { //only if control id ends with _UserField if(pp[i].id.indexOf(\'_UserField\', pp[i].id.length - \'_UserField\'.length) !== -1) { j++; if(j == pickerNo) { //this is the picker we are looking for result = pp[i]; break; } } } return result; }
The easiest way is to add the script to the new form of the SharePoint calendar using a Content Editor or Script Editor Web Part.
You can of course also use this script to set the default user for other columns, just change the number in the fillDefaultUser method in the script.