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%3CLINGO-SUB%20id%3D%22lingo-sub-1948510%22%20slang%3D%22en-US%22%3EBetreff%3A%20Using%20query%20variable%20in%20Modern%20Search%20Web%20Part%20(PnP%20web%20parts)%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1948510%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F153902%22%20target%3D%22_blank%22%3E%40Eva%20Vogel%3C%2FA%3E%26nbsp%3BHello%20%3A)%2C%20Do%20you%20know%20the%20solution%20for%20this%20question%3F%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1948790%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-1948790%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%20try%20this%3A%20advanced%20Metadata%20KQL%20query%20language%20is%20a%20tricky%20one%2C%20also%20with%20user-defined%20query%20criteria%20on%20the%20modern%20SP%20layout%20with%20the%20%22Highlighted%20Content%20Webpart%22%3A%20%3CA%20href%3D%22https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3Dtjvb5VV4lVE%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%22%3ESharePoint%20Power%20Hour%3A%20Advanced%20Managed%20Metadata%20%26amp%3B%20Search%20-%20YouTube%3C%2FA%3E%3C%2FP%3E%3CP%3EAll%20the%20best%20from%20Eva%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1951536%22%20slang%3D%22en-US%22%3EBetreff%3A%20Using%20query%20variable%20in%20Modern%20Search%20Web%20Part%20(PnP%20web%20parts)%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1951536%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F153902%22%20target%3D%22_blank%22%3E%40Eva%20Vogel%3C%2FA%3E%26nbsp%3B%3CSPAN%3ESolved.%20Token%20Page.FieldName%20must%20be%20placed%20in%20query%20template%20field%20in%20the%20web%20part%2C%20not%20in%20the%20query%20text%20Field.%20Thanks%3C%2FSPAN%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

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

@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.