CAML查询中的Sharepoint clientContext currentUser

时间:2018-09-02 20:07:43

标签: javascript sharepoint caml

我目前正在使用多种方法来获得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)
    );
}

我对使用clientContext功能不熟悉,但是对了解更多有关它以及如何解决此错误非常感兴趣。

谢谢!

1 个答案:

答案 0 :(得分:0)

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

import requests
from bs4 import BeautifulSoup as soup
def get_emails(_links:list):

for i in range(len(_links)):
 new_d = soup(requests.get(_links[i]).text, 'html.parser').find_all('a', {'class':'my_modal_open'})
 if new_d:
   yield new_d[-1]['title']

start = 20
while True:
d = soup(requests.get('http://www.schulliste.eu/type/gymnasien/?bundesland=&start={page_id}'.format(page_id=start)).text, 'html.parser')
results = [i['href'] for i in d.find_all('a')][52:-9]
results = [link for link in results if link.startswith('http://')]

items = list(get_emails(results))
for item in items:

    print(item)

next_page=d.find('div', {'class': 'paging'}, 'weiter')

if next_page:

    start+=20

else:
    break

无论如何,这个库大大简化了您的代码,所以我建议这样做: https://aymkdn.github.io/SharepointPlus/

代码类似于:

clientContext.load(currentUser, 'Title');

关于该问题的解释,我怀疑这与异步有关,即,在先前的函数为其分配了相关值之前,正在使用一个变量。