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

发布于:2024-05-13 ⋅ 阅读:(133) ⋅ 点赞:(0)

 问题:

当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


网站公告

今日签到

点亮在社区的每一天
去签到