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%2C%3C%2FP%3E%3CP%3EI%20am%20using%20the%20web%20part%20at%20%3CA%20href%3D%22https%3A%2F%2Fweb.archive.org%2Fweb%2F20201014031829%2Fhttps%3A%2F%2Fmicrosoft-search.github.io%2Fpnp-modern-search%2Fsearch-parts%2Fsearch-results%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noreferrer%22%3Ehttps%3A%2F%2Fweb.archive.org%2Fweb%2F20201014031829%2Fhttps%3A%2F%2Fmicrosoft-search.github.io%2Fpnp-modern-search%2Fsearch-parts%2Fsearch-results%3C%2FA%3E%20in%20a%20Communication%20Site%20and%20I%20am%20trying%20to%20set%20a%20dynamic%20query%20that%20depends%20on%20a%20page%20property.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EIf%20set%20the%20query%20with%20a%20fixed%20value%20as%3A%20path%3Ahttps%3A%2F%2F%3CTENANT%3E.sharepoint.com%2Fsites%2Fcontosonews%2FPhotos%20Company%3DMicrosoft%2C%20the%20results%20are%20correctly%20returned.%3C%2FTENANT%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EBut%20if%20I%20change%20my%20query%20to%20use%20a%20page%20property%20called%20Company%2C%20it%20doesn't%20work.%20I%20am%20using%20a%20query%20variable%20explained%20in%20the%20above%20article%20as%20follows%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3Epath%3Ahttps%3A%2F%2F%3CTENANT%3E.sharepoint.com%2Fsites%2Fcontosonews%2FPhotos%20Company%3D%7BPage.Company%7D%2C%20the%20results%20are%20correctly%20returned.%3C%2FTENANT%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EIMPORTANT%3A%20Company%20is%20a%20choice%20field%20and%20the%20user%20chooses%20in%20the%20Page%20Details%20the%20value%20of%20the%20Company%20field%20when%20editing%20the%20page.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ETried%20to%20use%20a%20managed%20property%20also%20but%20I%20have%20to%20get%20the%20dynamic%20value%20from%20the%20page%20data%20itself%20which%20I%20don't%20think%20it%20can%20be%20done%20through%20managed%20property.%20it%20must%20be%20a%20valid%20query%20variable%20as%20in%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2F...%2Ftechnical...%2Fquery-variables%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3Ehttps%3A%2F%2Fdocs.microsoft.com%2F...%2Ftechnical...%2Fquery-variables%3C%2FA%3E.%20This%20page%20refers%20Page.FieldName%20as%20the%20solution%20but%20couldn't%20get%20it%20to%20work%20yet.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EHow%20can%20I%20use%20the%20page%20property%20of%20type%20Choice%20(in%20this%20case%20called%20Company)%20in%20my%20search%20query%20to%20have%20a%20dynamic%20query%3F%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThanks%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
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