JavaScript in SharePoint works in Internet Explorer and not Chrome


March 2019


2 time


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 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(); = ctx.get_web();
this.currentUser = website.get_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);

function onFail(sender, args)
alert('request failed ' + args.get_message() + '\n'+ args.get_stackTrace());

0 answers