cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
RussellGove
Level 10

Returning sharepoint search results to powerapps from flow

I would like to be able to call the sharepoint search rest api  from my powerapps using flow.

 

I have a  standalone app that displays data from a list with many fields in a gallery. I want to be able to filter the items in the list based on a sharepoint search query. (i.e. I want to be able to let the user enter CustomerName=Contos* and have the view show only records where the field CustomerName  begins with ‘Contos’.

The powerapps search function works, but it queries all fields. I want to query on Specific fields using the search API.

I want to be able to call a flow, passing in the search query string ‘CustomerName=Contos*’  and the list of fields to return, and have the flow  call the sharepoint search API (_api/search/postquery)  and return the data in tabular format so that the gallery control can just switch between using list data and search results.

 

I  got it working by looping through all the results in @body('SPSearch')?['d']?['postquery']?['PrimaryQueryResult']?['RelevantResults']?['Table']?['Rows']?['results'] and then for each row looping through all of the columns and setting a temporary field to the value for that column, but it takes 10 minutes to run a simple query (because of the work being done in the for loop).

 

The issue is that the results from search look like this:

"results": [

    {

      "__metadata": {

        "type": "SP.SimpleDataRow"

      },

      "Cells": {

        "results": [

          {

            "__metadata": {

              "type": "SP.KeyValue"

            },

            "Key": "Rank",

            "Value": "27.591251373291",

            "ValueType": "Edm.Double"

          },

          {

            "__metadata": {

              "type": "SP.KeyValue"

            },

            "Key": "DocId",

            "Value": "17594549904503",

            "ValueType": "Edm.Int64"

          },

          {

            "__metadata": {

              "type": "SP.KeyValue"

            },

            "Key": "Title",

            "Value": "TiO2_BCN - GR Nanomaterials - V. Mathur",

            "ValueType": "Edm.String"

          },

          {

            "__metadata": {

              "type": "SP.KeyValue"

            },

            "Key": "ListItemID",

            "Value": "5678",

            "ValueType": "Edm.String"

          },

          {

            "__metadata": {

              "type": "SP.KeyValue"

            },

            "Key": "Created",

            "Value": "2014-06-27T14:46:49.0000000Z",

            "ValueType": "Edm.DateTime"

          },

          {

            "__metadata": {

              "type": "SP.KeyValue"

            },

            "Key": "IsClosedOWSCHCS",

            "Value": null,

            "ValueType": "Null"

          },

          {

            "__metadata": {

              "type": "SP.KeyValue"

            },

            "Key": "ContactEmailAddressOWSTEXT",

            "Value": null,

            "ValueType": "Null"

          },

          {

            "__metadata": {

              "type": "SP.KeyValue"

            },

            "Key": "CompanyOWSTEXT",

            "Value": null,

            "ValueType": "Null"

          },

          {

            "__metadata": {

              "type": "SP.KeyValue"

            },

            "Key": "RequestTextOWSMTXT",

            "Value": null,

            "ValueType": "Null"

          },

          {

            "__metadata": {

              "type": "SP.KeyValue"

            },

            "Key": "ResponseTextOWSMTXT",

            "Value": null,

            "ValueType": "Null"

          },

          {

            "__metadata": {

              "type": "SP.KeyValue"

            },

            "Key": "_ranking_features_",

            "Value": null,

            "ValueType": "Null"

          },

          {

            "__metadata": {

              "type": "SP.KeyValue"

            },

            "Key": "PartitionId",

            "Value": "9eec07e6-f6f8-4e24-b4c7-c5868500b417",

            "ValueType": "Edm.Guid"

          },

          {

            "__metadata": {

              "type": "SP.KeyValue"

            },

            "Key": "UrlZone",

            "Value": "0",

            "ValueType": "Edm.Int32"

          },

          {

            "__metadata": {

              "type": "SP.KeyValue"

            },

            "Key": "Culture",

            "Value": "en-US",

            "ValueType": "Edm.String"

          },

          {

            "__metadata": {

              "type": "SP.KeyValue"

            },

            "Key": "ResultTypeId",

            "Value": "0",

            "ValueType": "Edm.Int32"

          },

          {

            "__metadata": {

              "type": "SP.KeyValue"

            },

            "Key": "RenderTemplateId",

            "Value": "~sitecollection/_catalogs/masterpage/Display Templates/Search/Item_Default.js",

            "ValueType": "Edm.String"

          }

        ]

      }

    },

    {

      "__metadata": {

        "type": "SP.SimpleDataRow"

      },

      "Cells": {

        "results": [

          {

            "__metadata": {

              "type": "SP.KeyValue"

            },

            "Key": "Rank",

            "Value": "27.5383605957031",

            "ValueType": "Edm.Double"

          },

          {

            "__metadata": {

              "type": "SP.KeyValue"

            },

            "Key": "DocId",

            "Value": "17621262638504",

            "ValueType": "Edm.Int64"

          },

          {

            "__metadata": {

              "type": "SP.KeyValue"

            },

            "Key": "Title",

            "Value": "Prochazka, Jan ADVANCED MATERIALS JTJ",

            "ValueType": "Edm.String"

          },

          {

            "__metadata": {

              "type": "SP.KeyValue"

            },

            "Key": "ListItemID",

            "Value": "26",

            "ValueType": "Edm.String"

          },

          {

            "__metadata": {

              "type": "SP.KeyValue"

            },

            "Key": "Created",

            "Value": "2011-02-21T22:12:36.0000000Z",

            "ValueType": "Edm.DateTime"

          },

          {

            "__metadata": {

              "type": "SP.KeyValue"

            },

            "Key": "IsClosedOWSCHCS",

            "Value": null,

            "ValueType": "Null"

          },

          {

            "__metadata": {

              "type": "SP.KeyValue"

            },

            "Key": "ContactEmailAddressOWSTEXT",

            "Value": null,

            "ValueType": "Null"

          },

          {

            "__metadata": {

              "type": "SP.KeyValue"

            },

            "Key": "CompanyOWSTEXT",

            "Value": null,

            "ValueType": "Null"

          },

          {

            "__metadata": {

              "type": "SP.KeyValue"

            },

            "Key": "RequestTextOWSMTXT",

            "Value": null,

            "ValueType": "Null"

          },

          {

            "__metadata": {

              "type": "SP.KeyValue"

            },

            "Key": "ResponseTextOWSMTXT",

            "Value": null,

            "ValueType": "Null"

          },

          {

            "__metadata": {

              "type": "SP.KeyValue"

            },

            "Key": "_ranking_features_",

            "Value": null,

            "ValueType": "Null"

          },

          {

            "__metadata": {

              "type": "SP.KeyValue"

            },

            "Key": "PartitionId",

            "Value": "9eec07e6-f6f8-4e24-b4c7-c5868500b417",

            "ValueType": "Edm.Guid"

          },

          {

            "__metadata": {

              "type": "SP.KeyValue"

            },

            "Key": "UrlZone",

            "Value": "0",

            "ValueType": "Edm.Int32"

          },

          {

            "__metadata": {

              "type": "SP.KeyValue"

            },

            "Key": "Culture",

            "Value": "en-US",

            "ValueType": "Edm.String"

          },

          {

            "__metadata": {

              "type": "SP.KeyValue"

            },

            "Key": "ResultTypeId",

            "Value": "0",

            "ValueType": "Edm.Int32"

          },

          {

            "__metadata": {

              "type": "SP.KeyValue"

            },

            "Key": "RenderTemplateId",

            "Value": "~sitecollection/_catalogs/masterpage/Display Templates/Search/Item_Default.js",

            "ValueType": "Edm.String"

          }

        ]

      }

 

  ]

 

Anyone have any ideas how to turn the search results in the above  format into a regular ‘flat’  array  so that it can be returned to powerapps?

 

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
RussellGove
Level 10

Re: Returning sharepoint search results to powerapps from flow

I just found that search DOES let me choose which column to search . Still would be valuable to use SP search engine for more complex searches though and would help avoid delegation issues.

View solution in original post

2 REPLIES 2
RussellGove
Level 10

Re: Returning sharepoint search results to powerapps from flow

I just found that search DOES let me choose which column to search . Still would be valuable to use SP search engine for more complex searches though and would help avoid delegation issues.

View solution in original post

Community Support Team
Community Support Team

Re: Returning sharepoint search results to powerapps from flow

 

Hi @RussellGove ,

 

Have you found a suitable solution? If so, please click "Accept as Solution" on the reply that describes how describes you were able to solve your issue!

In addition, perhaps you could try to use the action Parse JSON-Filter array to achieve the need to filter the array.

Please check this article and see if it helps:

http://johnliu.net/blog/2018/6/a-thesis-on-the-parse-json-action-in-microsoft-flow

 

Best Regards,

Community Support Team _ Barry
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources

Announcements
firstImage

New Ranks and Rank Icons in April

Read the announcement for more information!

firstImage

Better Together Contest Finalists Announced!

Congrats to the finalists of our ‘Better Together’-themed T-shirt design contest! Click for the top entries.

firstImage

New & Improved Power Automate Community Cookbook

We've updated and improved the layout and uploading format of the Power Automate Cookbook!

thirdimage

Power Automate Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

sixthImage

Community Summit North America

The top training and networking event across the globe for Microsoft Business Applications

Top Solution Authors
Top Kudoed Authors
Users online (8,564)