JavaScript in SharePoint works in Internet Explorer and not Chrome

Refresh

2 weeks ago

Views

2 time

0

I have code from this post to set a people picker field in a SharePoint form to be the current user. It used to work in both ie and chrome, but now it only works in ie. Is there a change I can make to make it work in both or another way to accomplish the same goal that works in both?
I have this code in a webpart and in the JS section of DFFS, same results both places.

<script 
src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"> 
</script>
<script type="text/javascript">

$(document).ready(function () {
// Wait until SP.JS has loaded before calling getWebUserData 
ExecuteOrDelayUntilScriptLoaded(SetCurrentUsernameToPeoplePicker, "sp.js");
});

function SetCurrentUsernameToPeoplePicker()
{
var ctx = new SP.ClientContext.get_current();
this.website = ctx.get_web();
this.currentUser = website.get_currentUser();
ctx.load(currentUser);
ctx.executeQueryAsync(Function.createDelegate(this, this.onSucceess), 
Function.createDelegate(this, this.onFail));
}

function onSucceess(sender, args)
 {
var loginName = currentUser.get_loginName();
var form = $("table[class='ms-formtable']"); 
var userField = form.find("input[id$='ClientPeoplePicker_EditorInput']").get(1);
var peoplepicker = SPClientPeoplePicker.PickerObjectFromSubElement(userField);
peoplepicker.AddUserKeys(loginName);
 }

function onFail(sender, args)
{
alert('request failed ' + args.get_message() + '\n'+ args.get_stackTrace());
}
</script>

0 answers