SOLVED

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

%3CLINGO-SUB%20id%3D%22lingo-sub-1947699%22%20slang%3D%22en-US%22%3EUsing%20query%20variable%20in%20Modern%20Search%20Web%20Part%20(PnP%20web%20parts)%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1947699%22%20slang%3D%22en-US%22%3E%3CP%3EHello%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-1947699%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3ESharePoint%20Online%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1948010%22%20slang%3D%22de-DE%22%3ESubject%3A%20Using%20query%20variable%20in%20Modern%20Search%20Web%20Part%20(PnP%20web%20parts)%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1948010%22%20slang%3D%22de-DE%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F40896%22%20target%3D%22_blank%22%3E%40Miguel%20Lopes%20Isidoro%3C%2FA%3E%20so%20hello%3CIMG%20class%3D%22lia-deferred-image%20lia-image-emoji%22%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Fhtml%2Fimages%2Femoticons%2Fsmile_40x40.gif%22%20alt%3D%22%3Asmile%3A%22%20title%3D%22%3Asmile%3A%22%20%2F%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E
Contributor

Hello,

I am using the web part at https://web.archive.org/web/20201014031829/https://microsoft-search.github.io/pnp-modern-search/sear... 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

4 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)
Solution

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