Forum Discussion

miguelisidoro's avatar
miguelisidoro
Iron Contributor
Dec 02, 2020
Solved

Using query variable in Modern Search Web Part (PnP web parts) based on a Choice Page Property

Hello,

I am using the web part at https://web.archive.org/web/20201014031829/https://microsoft-search.github.io/pnp-modern-search/search-parts/search-results in a Communication Site and I am trying to set a dynamic query that depends on a page property.

 

If set the query with a fixed value as: path:https://<tenant>.sharepoint.com/sites/contosonews/Photos Company=Microsoft, the results are correctly returned.

 

But if I change my query to use a page property called Company, it doesn't work. I am using a query variable explained in the above article as follows:

 

path:https://<tenant>.sharepoint.com/sites/contosonews/Photos Company={Page.Company}, the results are correctly returned.

 

IMPORTANT: Company is a choice field and the user chooses in the Page Details the value of the Company field when editing the page.

 

Tried to use a managed property also but I have to get the dynamic value from the page data itself which I don't think it can be done through managed property. it must be a valid query variable as in https://docs.microsoft.com/.../technical.../query-variables. This page refers Page.FieldName as the solution but couldn't get it to work yet.

 

How can I use the page property of type Choice (in this case called Company) in my search query to have a dynamic query?

 

Thanks

  • Eva Vogel Solved. Token Page.FieldName must be placed in query template field in the web part, not in the query text Field. Thanks

6 Replies

Resources