• Get Multiple List Item Collection in single AJAX Call – Sharepoint JSOM


    We might have a scenario, where we need to access multiple List to get different result collection.

    JSOM allows us to send multiple CAML query in single ajax call – This save us load time, instead of making multiple ajax call we can do that in single ajax call.

    function retrieveMultipleListItems() {
        var ctx = SP.ClientContext.get_current();
        var oListTask = ctx.get_web().get_lists().getByTitle('Task1'); // Context of List1
        var oList = ctx.get_web().get_lists().getByTitle('Task2'); // Context of List2
        var queryString = '<View><Query><OrderBy><FieldRef Name='
        DueDate ' Ascending='
        true ' /></OrderBy></Query></View'; // CAML Query Sort by Date
        var query = new SP.CamlQuery();
        query.set_viewXml(queryString);
        var taskOpenQuery = '<View><Query>  <Where>    <Neq>      <FieldRef Name="Status"  />      <Value Type="Choice">Completed</Value>    </Neq> </Where></Query> </View> ' // CAML Query Filter
        var queryTask = new SP.CamlQuery();
        queryTask.set_viewXml(taskOpenQuery);
        this.collListItem1 = oListTask.getItems(query);
        ctx.load(collListItem1); // This contains First List Query  this.collListItem2 = oListTask.getItems(queryTask);
        ctx.load(collListItem2); // This contains Second List Query  
        ctx.executeQueryAsync(Function.createDelegate(this, this.GetMultipleListItemsSuccess), Function.createDelegate(this, this.GetMultipleListItemFailure));
    }
    
    function GetMultipleListItemsSuccess() {
        var listItemEnumerator = collListItem1.getEnumerator(); // Get collection of List 1 (collListItem1)
        while (listItemEnumerator.moveNext()) {
            var oListItem = listItemEnumerator.get_current();
            var id = oListItem.get_item('Title');
        }
    
        var listItemEnumerator1 = collListItem1.getEnumerator(); // Get collection of List 2 (collListItem2)
        while (listItemEnumerator1.moveNext()) {
            var oListItem = listItemEnumerator1.get_current();
            var id = oListItem.get_item('Title');
        }
    }
    
    function GetMultipleListItemFailure(sender, args) {
    alert('Request failed. ' + args.get_message() + '
    ' + args.get_stackTrace());
    }

    Now, You will get two collection results with single ajax call. We can Process each collection separately using getEnumerator().

    原文地址:http://techierocks.com/2017/11/get-multiple-list-item-collection-in-single-ajax-call-sharepoint-jsom.html

  • 相关阅读:
    zabbix 监控获取源码包的地址
    为MongoDB加集群验证的关键点
    Mongodb 集群加keyFile认证
    Prometheus完整的部署方案+实战实例
    如何让你的linux的命令行变得很炫
    redis实现加锁的几种方法示例详解
    phpquerylist 抓取数据详解
    mysql 主从配置,主-》windows,从-》centos6.5
    VMware 虚拟机centos下链接网络配置
    【Mysql】表链接
  • 原文地址:https://www.cnblogs.com/bjdc/p/10943236.html
Copyright © 2020-2023  润新知