1
我想從當前用戶的自定義列表中獲取列表計數。但是錯誤:(「Error:Sys.ArgumentNullException:Value can not be null。Parameter name:clientObject」)正在被拋出。代碼的第一部分,我必須得到當前用戶的屬性工作正常。我認爲PopulateEmployeeHeader(currentUser)導致錯誤。錯誤:Sys.ArgumentNullException:值不能爲空。參數名稱:clientObject
$(document).ready(function(){
// Ensure that the SP.UserProfiles.js file is loaded before the custom code runs.
SP.SOD.executeOrDelayUntilScriptLoaded(loadUserData, 'SP.UserProfiles.js');
$('#errorBase').hide();
});
var userProfileProperties;
var user;
function loadUserData(){
//Get Current Context
var clientContext = new SP.ClientContext.get_current();
//Get Instance of People Manager Class
var peopleManager = new SP.UserProfiles.PeopleManager(clientContext);
//Get properties of the current user
userProfileProperties = peopleManager.getMyProperties()
clientContext.load(userProfileProperties);
//Execute the Query.
clientContext.executeQueryAsync(onSuccess, onFail);
}
function onSuccess() {
var employeePhoto =userProfileProperties.get_pictureUrl();
PopulateEmployeeHeader(userProfileProperties.get_displayName());
if(employeePhoto !== undefined && employeePhoto !== "" && employeePhoto !== null)
{
$('#employeePicture').attr('src', userProfileProperties.get_pictureUrl());
}
else
{
$('results').innerHTML = "Picture does not exist in User Profiles list. Please upload your picture.";
}
}
function onFail(sender, args) {
alert("Error: " + args.get_message());
}
var oEmployee;
function PopulateEmployeeHeader(currentUser)
{
// var queryListItem = '<View><Query><Where><Eq><FieldRef Name="j2ur"/><Value Type="User">'+currentUser+'</Value></Eq></Where></Query></View>';
var queryListItem='<View><Query><Where><And><Eq><FieldRef Name="j2ur" />'+currentUser+'</Eq><IsNotNull><FieldRef Name="j2ur" />'+
+'</IsNotNull></And></Where></Query></View>';
var siteUrl = window.location.protocol + "//" + window.location.host+'/';
var clientContext = new SP.ClientContext(siteUrl);
var oEmployees = clientContext.get_web().get_lists().getByTitle('Accounts');
var myquery = new SP.CamlQuery();
myquery.set_viewXml(queryListItem);
this.oEmployee= oEmployees.getItems(myquery);
clientContext.load(oEmployee);
clientContext.executeQueryAsync(
Function.createDelegate(this, this.onEmployeeSucceeded),
Function.createDelegate(this, this.onEmployeeFailed)
);
}
function onEmployeeSucceeded(sender, args) {
alert(oEmployee.get_count());
}
function onEmployeeFailed(sender, args) {
alert('Request failed. ' + args.get_message() +'\n' + args.get_stackTrace());
}
})(jQuery);
您是否嘗試過沒有SP.SOD.executeOrDelayUntilScriptLoaded(loadUserData, 'SP.UserProfiles.js')運行; ?只需要 $(document).ready(function(){ loadUserData $('#errorBase')。hide(); }); –
這也沒有工作:(我最終做的是重新分解代碼。謝謝你的迴應! –