SharePoint 使用renderListDataAsStream方法查询list超过5000时的数据

 问题:

当SharePoint List里的数据超过5000时,如果使用常用的rest api去获取数据,例如

await this.sp.web.lists.getByTitle('Document Library').rootFolder.files.select('*, listItemAllFields').expand('listItemAllFields').filter(`listItemAllFields/testID eq '1111'`)()

或

await this.sp.web.lists.getByTitle('xxx').items.filter(`Status eq '${status}'`).top(5000)()

Api会报错,提示list里的数据超过5000

解决方法: 

使用renderListDataAsStream() 方法,用xml语句的形式获取数据。

import { IRenderListDataParameters } from '@pnp/sp/lists';

const query: IRenderListDataParameters = {
            ViewXml: `<View>
            <RowLimit Paged="TRUE">5000</RowLimit>
            <Query>
              <Where>
                <And>
                    <Or>
                        <Contains>
                            <FieldRef Name='Title'/><Value Type='Text'>${title}</Value>
                        </Contains>
                        <Contains>
                            <FieldRef Name='ID'/><Value Type='Text'>${id}</Value>
                        </Contains>
                    </Or>
                    <Eq>
                        <FieldRef Name='Status'/>
                        <Value Type='Text'>${status}</Value>
                    </Eq>
                </And>
              </Where>
            </Query>
          </View>`,
          Paging:lastHref ? lastHref.substring(1):undefined        
        }
        return this._web.lists.getByTitle('xxx').renderListDataAsStream(query).then(async (result:any) => {
            return result.Row
        });

 注意事项:

 如果获取数据有filter条件,需要将检索的参数设置index,

设置index的方式可以参考下方官方文档

Add an index to a list or library column - Microsoft Support

相关推荐

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-05-11 20:12:02       98 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-05-11 20:12:02       106 阅读
  3. 在Django里面运行非项目文件

    2024-05-11 20:12:02       87 阅读
  4. Python语言-面向对象

    2024-05-11 20:12:02       96 阅读

热门阅读

  1. mysql5.x 的某些神奇问题

    2024-05-11 20:12:02       31 阅读
  2. 全志A133 android10 增加开机脚本

    2024-05-11 20:12:02       28 阅读
  3. Hive优化(1)——分桶采样

    2024-05-11 20:12:02       33 阅读
  4. Django调用SECRET_KEY对数据进行加密

    2024-05-11 20:12:02       29 阅读
  5. 905. 按奇偶排序数组

    2024-05-11 20:12:02       30 阅读