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



I am using the web part at 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> 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> 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 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?



6 Replies

@Eva Vogel Hello :), Do you know the solution for this question?

@Miguel Lopes Isidoro try this: advanced Metadata KQL query language is a tricky one, also with user-defined query criteria on the modern SP layout with the "Highlighted Content Webpart": SharePoint Power Hour: Advanced Managed Metadata & Search - YouTube

All the best from Eva

best response confirmed by Miguel Lopes Isidoro (Contributor)

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

@Miguel Lopes Isidoro 

we have the same problem. Could You please explain the solution better? With the example…

@Roco_Alvarez_Moret check the attached image.