I have a SPFeatureReceiver that adding to calendar item new button in ribbon:
SPUserCustomAction getTheTerm = list.UserCustomActions.Add();
getTheTerm.CommandUIExtension = $@"
<CommandUIExtension>
<CommandUIDefinitions>
<CommandUIDefinition Location=""Ribbon.ListForm.Display.Manage.Controls._children"">
<Button Id=""{getTheTerminBId}"" Sequence=""1"" TemplateAlias=""o1""
Image16by16=""_layouts/15/Images/SYG_ScheduleTest/icons8_today_48px.png""
Image32by32=""_layouts/15/Images/SYG_ScheduleTest/icons8_today_48px.png""
Command=""{getTheTerminCId}"" CommandType=""General"" LabelText=""Zapisz się"" />
</CommandUIDefinition>
</CommandUIDefinitions>
<CommandUIHandlers>
<CommandUIHandler Command =""{getTheTerminCId}""
CommandAction=""javascript: setNewUser();"" />
</CommandUIHandlers>
</CommandUIExtension>";
getTheTerm.Update();
ar scriptlink = web.UserCustomActions.Add();
scriptlink.Location = "ScriptLink";
scriptlink.ScriptSrc = "/_layouts/15/SYG_ScheduleTest/JavaScriptModel_1.js";
scriptlink.Update();
And the JavaScriptModel_1.js:
function setNewUser() {
var clientContext = SP.ClientContext.get_current();
var oList;
oList = clientContext.get_web().get_lists().getById(_spPageContextInfo.pageListId);
clientContext.load(oList);
clientContext.executeQueryAsync(Function.createDelegate(this, success), Function.createDelegate(this, fail));
var oListItem = oList.getItemById(parseInt(GetUrlKeyValue('ID')));
clientContext.load(oListItem);
clientContext.executeQueryAsync(Function.createDelegate(this, success), Function.createDelegate(this, fail));
currentUserId = _spPageContextInfo.userId;
AddStatusMessage(currentUserId, 'green');
currentUserLogin = SP.ClientContext.get_current().get_web().get_currentUser().get_loginName();
clientContext.load(currentUserLogin, 'LoginName');
clientContext.executeQueryAsync(Function.createDelegate(this, success), Function.createDelegate(this, fail));
AddStatusMessage(currentUserLogin, 'green');
}
_spBodyOnLoadFunctionNames.push(function () {
ExecuteOrDelayUntilScriptLoaded(setNewUser, "sp.js");
});
Generally all work fine but i cannot get to verbose LoginName. In Add Status Message a get Error: The property or field 'LoginName' has not been initialized. But if a try to access that property via browser console I can read login.
I thinking that the problem in the wrong turn of execution java scripts. After click in button not all are load but in console are. But i'm not sure.
In long term I need update multi user field by adding current user.