This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var clientContext; | |
SP.SOD.executeFunc("sp.js", 'SP.ClientContext', function () { | |
clientContext = new SP.ClientContext.get_current(); | |
var oWeb = clientContext.get_web(); | |
var strUserName = _spPageContextInfo.userLoginName; | |
var listName = "MyList"; | |
if (strUserName) { | |
var oUser = new Array(); | |
oUser.push(SP.FieldUserValue.fromUser(strUserName.substring(0, strUserName.indexOf("@")))); | |
var oList = oWeb.get_lists().getByTitle(listName); | |
var itemCreateInfo = new SP.ListItemCreationInformation(); | |
var oListItem = oList.addItem(itemCreateInfo); | |
oListItem.set_item('UserName', oUser); | |
oListItem.update(); | |
clientContext.executeQueryAsync(onQuerySucceeded, onQueryFailedInsert); | |
} | |
}); | |
onQuerySucceeded = function (response) { | |
console.log('success'); | |
} | |
onQueryFailedInsert = function (sender, args) { | |
console.log('failure'); | |
} |