Trying to figure out why I am getting this error with my code, am I missing a script reference, or is perhaps something wrong with the Context data grab section?
Error:
The property or field 'Email' has not been initialized. It has not been requested or the request has not been executed. It may need to be explicitly requested.
Script references in Web Part Page:
<SharePoint:ScriptLink name="clienttemplates.js" runat="server" LoadAfterUI="true" Localizable="false"/>
<SharePoint:ScriptLink name="clientforms.js" runat="server" LoadAfterUI="true" Localizable="false"/>
<SharePoint:ScriptLink name="clientpeoplepicker.js" runat="server" LoadAfterUI="true" Localizable="false"/>
<SharePoint:ScriptLink name="autofill.js" runat="server" LoadAfterUI="true" Localizable="false"/>
<SharePoint:ScriptLink name="sp.RequestExecutor.js" runat="server" LoadAfterUI="true" Localizable="false"/>
<SharePoint:ScriptLink name="sp.js" runat="server" LoadAfterUI="true" Localizable="false"/>
<SharePoint:ScriptLink name="sp.runtime.js" runat="server" LoadAfterUI="true" Localizable="false"/>
<SharePoint:ScriptLink name="sp.core.js" runat="server" LoadAfterUI="true" Localizable="false"/>
<SharePoint:ScriptLink name="SP.Debug.js" runat="server" LoadAfterUI="true" Localizable="false"/>
<SharePoint:ScriptLink name="SP.Runtime.Debug.js" runat="server" LoadAfterUI="true" Localizable="false"/>
Code:
///////////////////Enable JSOM Intellisense for MS Visual Studio////////////////////////////////////////////////////////////////////////
/// <reference path="C:\Program Files\Common Files\microsoft shared\Web Server Extensions\15\TEMPLATE\LAYOUTS\clienttemplates.js" />
/// <reference path="C:\Program Files\Common Files\microsoft shared\Web Server Extensions\15\TEMPLATE\LAYOUTS\clientforms.js" />
/// <reference path="C:\Program Files\Common Files\microsoft shared\Web Server Extensions\15\TEMPLATE\LAYOUTS\clientpeoplepicker.js" />
/// <reference path="C:\Program Files\Common Files\microsoft shared\Web Server Extensions\15\TEMPLATE\LAYOUTS\autofill.js" />
/// <reference path="C:\Program Files\Common Files\microsoft shared\Web Server Extensions\15\TEMPLATE\LAYOUTS\sp.RequestExecutor.js" />
/// <reference path="C:\Program Files\Common Files\microsoft shared\Web Server Extensions\15\TEMPLATE\LAYOUTS\sp.js" />
/// <reference path="C:\Program Files\Common Files\microsoft shared\Web Server Extensions\15\TEMPLATE\LAYOUTS\sp.runtime.js" />
/// <reference path="C:\Program Files\Common Files\microsoft shared\Web Server Extensions\15\TEMPLATE\LAYOUTS\sp.core.js" />
/// <reference path="C:\Program Files\Common Files\microsoft shared\Web Server Extensions\15\TEMPLATE\LAYOUTS\sp.debug.js" />
/// <reference path="C:\Projects\jquery\VsDoc\jquery-1.4.4-vsdoc.js" />
//////////////////////////////////////////////////////////////////////////////////////////////////////////
v_item = '';
$(
function () {
if (typeof (_spBodyOnLoadWrapper) != 'undefined') { _spBodyOnLoadWrapper(); }
ExecuteOrDelayUntilScriptLoaded(getDivision_Chief_User, "sp.js");
});
function getDivision_Chief_User() {
var clientContext = new SP.ClientContext.get_current();
var web = clientContext.get_web();
var list = web.get_lists().getByTitle('myTestList');
v_item = list.getItemById(1);
clientContext.load(v_item);
clientContext.executeQueryAsync(onSuccess, onFailure);
}
function onSuccess(sender, args) {
var context = SP.ClientContext.get_current();
var web = context.get_web();
var userName = v_item.get_item('myPersonLookUpField').get_lookupValue();
var user = web.ensureUser(userName);
//ERROR HAPPENS HERE WHEN DEBUGING IN BROWSER
var email = user.get_email();
var loginName = user.get_loginName();
var v_Id = user.get_id();
var v_Title = user.get_title();
alert('The Display Name of the user is ' + email);
alert('The Account Name of the user is ' + loginName);
alert('The email address of the user is ' + v_Id);
alert('The User Title is ' + v_Title);
//$("#h_ValueWritter").html(v_commentsTemp);
}
function onFailure(sender, args) {
console.log('Failure!');
}