Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/sharepoint/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript CAML查询中的Sharepoint clientContext currentUser_Javascript_Sharepoint_Caml - Fatal编程技术网

Javascript CAML查询中的Sharepoint clientContext currentUser

Javascript CAML查询中的Sharepoint clientContext currentUser,javascript,sharepoint,caml,Javascript,Sharepoint,Caml,我目前正在使用多种方法来获取SharePoint 2013中的当前用户,以便能够自动查询登录用户的数据集 我遇到了一个奇怪的错误,如果我不在retrieveListItems函数中使用警报框,我会得到SCRIPT438:对象不支持属性或方法“get_$y_0”。如果我放一个简单的警报(“嗨”);在这个函数的开头,我没有得到错误,我的图表也没有正确地呈现给用户 下面是我的(草率的)代码,但如果有人能提供任何见解,说明为什么会这样做,以及我如何确保在不使用任何警报框的情况下解决错误,我将非常感激 E

我目前正在使用多种方法来获取SharePoint 2013中的当前用户,以便能够自动查询登录用户的数据集

我遇到了一个奇怪的错误,如果我不在retrieveListItems函数中使用警报框,我会得到SCRIPT438:对象不支持属性或方法“get_$y_0”。如果我放一个简单的警报(“嗨”);在这个函数的开头,我没有得到错误,我的图表也没有正确地呈现给用户

下面是我的(草率的)代码,但如果有人能提供任何见解,说明为什么会这样做,以及我如何确保在不使用任何警报框的情况下解决错误,我将非常感激

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)
    );
}
executeOrderLayintlScriptLoaded(init,“sp.js”);
无功电流用户;
函数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));
}
函数onQueryFailed2(){
警报(“2”);
}
函数retrieveUser(){
currentUser=currentUser.get_title();
//警报(当前用户);
this.clientContext.load(currentUser);
this.clientContext.executeQueryAsync(
Function.createDelegate(this,this.retrieveListItems),
Function.createDelegate(this,this.onQueryFailed2)
)
}
//根据列表名称从上述sharepoint网站检索列表数据
函数retrieveListItems(){
load(currentUser,'Title');
//警报('呈现…');
//var clientContext=new SP.clientContext(siteUrl);
var oList=clientContext.get_web().get_list().getByTitle('APS公文包');
var camlQuery=new SP.camlQuery();
//currentUser='Fox,Natalie G';
//加载(当前用户);
camlQuery.set_viewXml(“+currentUser+”);
this.collListItem=oList.getItems(camlQuery);
加载(collListItem);
clientContext.executeQueryAsync(
Function.createDelegate(this,this.onquerySucceed),
Function.createDelegate(this,this.onQueryFailed)
);
}
我不熟悉使用clientContext功能,但我非常有兴趣了解更多关于它的信息,以及我可以做些什么来解决这个错误


谢谢大家!

不太清楚为什么retrieveListItems()的第一行是:

无论如何,这个库大大简化了您的代码,因此我建议您:

代码类似于:

$SP().list("My List").get({
  fields:"Title",//whatever fields you want
  where:"Author = '[Me]'"//[Me] is the current user that is logged in
}).then(function(row) {
  console.log(row[0].getAttribute("Title"));
});
关于这个问题的解释,我怀疑这与async有关,也就是说,一个变量在被前一个函数赋值之前就已经被使用了

$SP().list("My List").get({
  fields:"Title",//whatever fields you want
  where:"Author = '[Me]'"//[Me] is the current user that is logged in
}).then(function(row) {
  console.log(row[0].getAttribute("Title"));
});