0
点赞
收藏
分享

微信扫一扫

【Power Automate】在Power Automate中使用SharePoint Search Query Rest Api以及处理返回结果大于500条的情况

前言

实现步骤

由于内容较多,篇幅可能会很长很长,大家一定要耐心,哈哈

1、初始化变量

说明:初始化站点地址weburl、请求rest api、文件总数rowcount、每次请求数量rowlimit、页数pagecount、开始的索引startrow

  

2、获取文件总数,根据总数/500计算出需要请求几次

说明:

a、SharePoint Search Rest Api每次请求只能返回500条数据

b、rowcount:outputs('SharePointHttp')?['body']['PrimaryQueryResult']['RelevantResults']['TotalRows']  , 如1034

 c、pagecount:if(greater(mod(variables('rowcount'),variables('rowlimit')),0),add(div(variables('rowcount'),variables('rowlimit')),1),div(variables('rowcount'),variables('rowlimit'))),结果为3

 d、pagecountarray:range(0,variables('pagescount')) ,结果为[1,2,3]

 完整截图如下

 3、根据pagecountarray循环请求SharePoint search rest api返回所有文件数据

说明:接下来相关操作在”应用到每一个”操作中

a、设置每次请求的开始索引,以及设置rest api

 

 b、请求SharePoint search rest api并对结果进行处理分析

说明:由于每次请求返回500条,请求返回后需要再次循环这500条数据,进行相关操作

 c、获取每次请求总数,注意是rowcount,不是 totalcount,然后生成数组

说明:

EachRowCount:outputs('SharePointHttp')?['body']['PrimaryQueryResult']['RelevantResults']['RowCount']

EachRowCountArray:range(0,variables('EachRowCount'))

 d、循环每次请求的结果,根据需求获取所需的属性值(重要)

说明:

这里有个小逻辑,由于要获取文档下载量、访问量等, 而这些数据在另外一张表中存储的,所以要通过唯一键uniqueid进行筛选关联,如下图等于后面的值需要从刚刚获取的结果中获取,获取表达式如下,且uniqueid的属性在cells中索引为10(数据结构放置于最后,可参考),故写作如下

outputs('SharePointHttp')?['body']['PrimaryQueryResult']['RelevantResults']['Table']['Rows'][int(variables('EachRowIndexStr'))]['Cells'][10]['Value']

 完整图片如下

 e、最后一步,把请求返回来的数据插入到自定义列表中

说明:此处用了一个判断,如果有下载量、访问量等,则将相关数据插入列表中,否则插入0

每个字段属性获取数据格式:

fileSize
outputs('SharePointHttp')?['body']['PrimaryQueryResult']['RelevantResults']['Table']['Rows'][int(variables('EachRowIndexStr'))]['Cells'][2]['Value']

path
outputs('SharePointHttp')?['body']['PrimaryQueryResult']['RelevantResults']['Table']['Rows'][int(variables('EachRowIndexStr'))]['Cells'][3]['Value']

LastModifiedTime
outputs('SharePointHttp')?['body']['PrimaryQueryResult']['RelevantResults']['Table']['Rows'][int(variables('EachRowIndexStr'))]['Cells'][4]['Value']

Created
outputs('SharePointHttp')?['body']['PrimaryQueryResult']['RelevantResults']['Table']['Rows'][int(variables('EachRowIndexStr'))]['Cells'][4]['Value']

结语

附录

数据结构

{
                            "Cells": [
                                {
                                    "Key": "Rank",
                                    "Value": "-15.2993106",
                                    "ValueType": "Edm.Double"
                                },
                                {
                                    "Key": "DocId",
                                    "Value": "1846139039222474042",
                                    "ValueType": "Edm.Int64"
                                },
                                {
                                    "Key": "Size",
                                    "Value": "516701",
                                    "ValueType": "Edm.Int64"
                                },
                                {
                                    "Key": "Path",
                                    "Value": "docurl",
                                    "ValueType": "Edm.String"
                                },
                                {
                                    "Key": "LastModifiedTime",
                                    "Value": "2021-10-19T04:58:18.0000000Z",
                                    "ValueType": "Edm.DateTime"
                                },
                                {
                                    "Key": "FileExtension",
                                    "Value": "aspx",
                                    "ValueType": "Edm.String"
                                },
                                {
                                    "Key": "IsDocument",
                                    "Value": "false",
                                    "ValueType": "Edm.Boolean"
                                },
                                {
                                    "Key": "FileType",
                                    "Value": "jpg",
                                    "ValueType": "Edm.String"
                                },
                                {
                                    "Key": "SPWebUrl",
                                    "Value": "weburl",
                                    "ValueType": "Edm.String"
                                },
                                {
                                    "Key": "SiteName",
                                    "Value": "siteurl",
                                    "ValueType": "Edm.String"
                                },
                                {
                                    "Key": "UniqueId",
                                    "Value": "9221e73f-****-460c-9312-7dc46e326219",
                                    "ValueType": "Edm.String"
                                },
                                {
                                    "Key": "OriginalPath",
                                    "Value": "docurl",
                                    "ValueType": "Edm.String"
                                },
                                {
                                    "Key": "Title",
                                    "Value": "39、0007--LEAP软件测试报告",
                                    "ValueType": "Edm.String"
                                },
                                {
                                    "Key": "Filename",
                                    "Value": "39、0007--LEAP软件测试报告.jpg",
                                    "ValueType": "Edm.String"
                                },
                                {
                                    "Key": "SiteId",
                                    "Value": "bf0897ac-****-49e4-8e6e-cddec81ba624",
                                    "ValueType": "Edm.String"
                                },
                                {
                                    "Key": "WebId",
                                    "Value": "f6490448-****-406d-b321-eb51398b6ee1",
                                    "ValueType": "Edm.String"
                                },
                                {
                                    "Key": "contentclass",
                                    "Value": "STS_ListItem_DocumentLibrary",
                                    "ValueType": "Edm.String"
                                },
                                {
                                    "Key": "IsExternalContent",
                                    "Value": "false",
                                    "ValueType": "Edm.Boolean"
                                },
                                {
                                    "Key": "ListId",
                                    "Value": "d94a516a-****-49a8-9e55-c3f7deed73e5",
                                    "ValueType": "Edm.String"
                                },
                                {
                                    "Key": "PartitionId",
                                    "Value": "5c7d0b28-****-410c-aa93-4df372b16203",
                                    "ValueType": "Edm.Guid"
                                },
                                {
                                    "Key": "UrlZone",
                                    "Value": "0",
                                    "ValueType": "Edm.Int32"
                                },
                                {
                                    "Key": "Culture",
                                    "Value": "zh-CN",
                                    "ValueType": "Edm.String"
                                },
                                {
                                    "Key": "ResultTypeId",
                                    "Value": "0",
                                    "ValueType": "Edm.Int32"
                                },
                                {
                                    "Key": "RenderTemplateId",
                                    "Value": "~sitecollection/_catalogs/masterpage/Display Templates/Search/Item_Default.js",
                                    "ValueType": "Edm.String"
                                },
                                {
                                    "Key": "GeoLocationSource",
                                    "Value": "APC",
                                    "ValueType": "Edm.String"
                                },
                                {
                                    "Key": "piSearchResultId",
                                    "Value": "ARIAǂ0495ac0a-6b23-8025-050c-1ecea3dfc77cǂc7c150a8-3a22-404d-94be-2d5e6dea3d4fǂ0495ac0a-6b23-8025-050c-1ecea3dfc77c.1000.126ǂ",
                                    "ValueType": "Edm.String"
                                }
                            ]
                        }
举报

相关推荐

0 条评论