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

  • 5
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值