SharePoint Online列表加入Caml查询

时间:2018-10-04 08:04:56

标签: sharepoint-online sharepoint-designer sharepoint-jsom

我在SharePoint在线网站上有2个列表。

  1. 会员(编号,姓名)
  2. 会员地址(会员(查看会员列表),地址)

预期结果:

ID,名称,地址

我正在尝试使用Join查询从两个列表中获取数据,但出现错误。 我的代码和错误如下:

<script type="text/javascript">
function useRESTwithCAML(CAML) {
    var clientContext = new SP.ClientContext.get_current();
    var oList = clientContext.get_web().get_lists().getByTitle('Members');

    var camlQuery = new SP.CamlQuery();
    camlQuery.set_viewXml(CAML);
    this.collListItem = oList.getItems(camlQuery);

    clientContext.load(collListItem);
    clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed));

};

var CAMLJoins =
    "<Joins>" +
    "<Join Type='LEFT' ListAlias='Member Address'>" +
    "<Eq>" +
    "<FieldRef Name='ID' RefType='Id'/>" +
    "<FieldRef List='Member Address' Name='Member'/>" +
    "</Eq>" +
    "</Join></Joins>";

var CAMLProjFlds =
    "<ProjectedFields>" +
    "<Field Name='Address' Type='Number' List='Address' ShowField='ID'/>" +
    "</ProjectedFields>";

var ViewXml = "<View>" +
    "<ViewFields>" +
    "<FieldRef Name='Name'/>" +
    "</ViewFields>" + CAMLJoins +
    "</View>";
function onQuerySucceeded(sender, args) {

    var listItemInfo = '';

    var listItemEnumerator = collListItem.getEnumerator();

    while (listItemEnumerator.moveNext()) {
        var oListItem = listItemEnumerator.get_current();
        listItemInfo += '\nID: ' + oListItem.get_id() +
            '\nTitle: ' + oListItem.get_item('Name') +
            '\nDLastName: ' + oListItem.get_item('Address');
    }

    alert(listItemInfo.toString());
}

function onQueryFailed(sender, args) {

    alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
}

我遇到以下错误:

"Value does not fall within the expected range."

我还有10个列表,每个列表都有“成员”查找列,我想将它们全部加入。请让我知道我是否缺少任何东西或做错了什么。

谢谢。

0 个答案:

没有答案