【发布时间】:2018-10-10 18:47:29
【问题描述】:
我目前正在使用多种方式来获取 SharePoint 2013 中的当前用户,以便我可以自动查询登录用户的数据集。
我遇到了一个奇怪的错误,如果我没有在我的 retrieveListItems 函数中使用警告框,我会得到 SCRIPT438:对象不支持属性或方法“get_$y_0”。如果我放一个简单的 alert('Hi');在此函数开始时,我没有收到错误,并且我的图表为用户正确呈现。
下面是我的(草率的)代码,但如果有人能提供任何关于它为什么会这样做以及我如何确保在不使用任何警报框的情况下解决错误的见解,我将非常感激。
ExecuteOrDelayUntilScriptLoaded(init,"sp.js");
var currentUser;
function init(){
this.clientContext = new SP.ClientContext.get_current();
this.oWeb = clientContext.get_web();
currentUser = this.oWeb.get_currentUser();
this.clientContext.load(currentUser);
this.clientContext.executeQueryAsync(Function.createDelegate (this,this.retrieveUser), Function.createDelegate(this,this.onQueryFailed2));
}
function onQueryFailed2(){
alert('2');
}
function retrieveUser(){
currentUser = currentUser.get_title();
//alert(currentUser);
this.clientContext.load(currentUser);
this.clientContext.executeQueryAsync(
Function.createDelegate(this,this.retrieveListItems),
Function.createDelegate(this,this.onQueryFailed2)
)
}
//retrieve list data from above sharepoint site based on List Name
function retrieveListItems() {
clientContext.load(currentUser, 'Title');
//alert('Rendering...');
//var clientContext = new SP.ClientContext(siteUrl);
var oList = clientContext.get_web().get_lists().getByTitle('APS Portfolio');
var camlQuery = new SP.CamlQuery();
//currentUser = 'Fox, Natalie G';
//clientContext.load(currentUser);
camlQuery.set_viewXml("<View><Query><Where><Eq><FieldRef Name='AIT_x0020_App_x0020_Manager'/><Value Type='Text'>" +currentUser+ "</Value></Eq></Where></Query></View>");
this.collListItem = oList.getItems(camlQuery);
clientContext.load(collListItem);
clientContext.executeQueryAsync(
Function.createDelegate(this, this.onQuerySucceeded),
Function.createDelegate(this, this.onQueryFailed)
);
}
我是使用 clientContext 功能的新手,但我非常有兴趣了解有关它的更多信息以及我可以做些什么来解决此错误。
谢谢!
【问题讨论】:
标签: javascript sharepoint caml