function Peoplepicker () {this.context = null; This.web = null; This.currentuser = null; This.parenttagid = null this. Setparenttagid = function (id) {this.parenttagid = ID; } this. Setloggedinuser = function () {if (This.parenttagid! = null) {this.getwebuserdata (); }} this.getwebuserdata = function () {this.context = new SP. Clientcontext.get_current (); This.web = This.context.get_web (); This.currentuser = This.web.get_currentUser (); This.currentUser.retrieve (); This.context.load (This.web); This.context.executeQueryAsync (Function.createdelegate (this, This.onsuccessmethod), Function.createdelegate (this, this.onfailuremethod)); } This.onsuccessmethod = function () {This.setdefaultvalue (This.currentUser.get_title ()); } This.onfailuremethod = function () {alert (' request failed ' + args.get_message () + ' \ n ' + args.get_stackTrace ()); } This.setdefaultvalue = function (value) {var Parenttag = document.getElementById (This.parenttagid); if (Parenttag! = null) {var _ppe = $ ("input[title= '" + $ (parenttagid). attr (' title ') + "']"); _ppe.val (value); var _ppo = Spclientpeoplepicker.spclientpeoplepickerdict[this.parenttagid]; _ppo. Addunresolveduserfromeditor (TRUE); }}}function Setwebuserdata () {var pplpicker = new Peoplepicker (); var controlId = $ (' Td.ms-formlabel:contains (' field name ') '). Siblings (' TD '). FIND (' div[title= ' field name '] '). Prop ("ID "); Pplpicker.setparenttagid (CONTROLID); Pplpicker.setloggedinuser ();} $ (document). Ready (function () {executeordelayuntilscriptloaded (Setwebuserdata, "sp.js");});
[SharePoint 2013] Set value for people editor with JSOM