Using KQL To Force “AND” in SharePoint Highlighted Content Web Parts

Tech
September 22, 2021

Certain restrictions in SharePoint Online web parts can have limited functionality, getting in the way of what you are trying to achieve. The SharePoint Highlighted Content Web Part is a great example of this, as it does not allow the user to combine an “AND” on managed properties. In this tutorial, we will demonstrate how to do so.

In order to force this combination, first go to the “Custom Query” capability of the SharePoint Highlighted Content Web Part. Here, you can build your own query through the Keyboard Query Language (KQL).

For example, if you are building a web part that will show news that is set as a highlight, but you only want to show news types of “CEO” or “Learning”, this cannot be achieved due to the restrictions in SharePoint’s out of the box news web part. Any managed property will become an “OR”. To make sense of this, the following graph is a great source to gain a better understanding of how Highlighted Content Web Part logic works.

This “OR” restriction means it would be a highlight OR it would be a Learning OR CEO news. It would continue by using only one of these types.

Important information before continuing:

  • “IsDocument:1” means that you are looking for a document.
  • “PromotedState:2” means you are looking for news.

In the above scenario, the first step is setting up the news you are looking for (PromotedState:2).

Next, identify the managed property name of the field. In this example, you know that the column name is “News Type“, as that’s what you see in your library and where you set the news type when posting news.

To find the managed property, go to the gear icon > site contents > site settings > schema.

Once there, you will type a part of our column name. The managed property name will appear, as seen below. Our “News Type” is actually “owstaxIdNewsType” – this is SharePoint’s internal name that it shares across the sites for tracking purposes.

Next, update your query:  (PromotedState: 2  AND  owstaxIdNewsType:)

Now you are able to input what you would like the News Type to be in the query. To do that, first append the text “GP0|#“, this prepares the query that you will be looking for a specific term from a term store.

(PromotedState: 2  AND  owstaxIdNewsType:GP0|#)

Now, go into the term store, browse for your term, and grab it’s GUID and it’s term name. The term name in this example is “Learning”.

In the term store, click on the term. You will find the GUID at the very bottom.

The query gets updated again, but note the specifics of this one: the GUID, then the term.

(PromotedState: 2  AND owstaxIdNewsType:GP0|#cf880322-06ba-4066-9bf5-375b4d18314b:”Learning”)

Repeat the action for the “CEO” Updates, but first, to be clear in your query that it is “Learning” OR “CEO” and the other pieces are non-negotiable, put it between new brackets.

(PromotedState: 2  AND (owstaxIdNewsType:GP0|#c6bcf9b0-f056-41fb-a877-c490aee72a83:”CEO”) OR (owstaxIdNewsType:GP0|#cf880322-06ba-4066-9bf5-375b4d18314b:”Learning”))

Finally, only show items where “HighlightNews” is equal to Yes. If you recall when originally looking for the NewsType managed property, you’ll notice Highlight also appeared there. Put this at the beginning of your query, with the other non-negotiable (the PromotedState): This AND This (this OR this)

(PromotedState: 2 AND HighlightNewsOWSCHCS: (owstaxIdNewsType:GP0|#c6bcf9b0-f056-41fb-a877-c490aee72a83:”CEO”) OR (owstaxIdNewsType:GP0|#cf880322-06ba-4066-9bf5-375b4d18314b:”Learning”))

The final touch is adding the “Yes”, and, since the Highlight column is just a choice column, not managed metadata, no GUID is needed.

(PromotedState: 2  AND HighlightNewsOWSCHCS: “Yes” (owstaxIdNewsType:GP0|#c6bcf9b0-f056-41fb-a877-c490aee72a83:”CEO”) OR (owstaxIdNewsType:GP0|#cf880322-06ba-4066-9bf5-375b4d18314b:”Learning”))

Putting this into the KQL Query box in the Highlighted Content Web Part will do the trick!

​​​​​​​The configured web part is below.

And here is an example of our beautiful published SharePoint news web part showing posts with the properties “CEO” and “Learning.”

THE AUTHOR

Rhia Wieclawek - Elantis Business Process Automation Practice DirectorRhia Wieclawek – Director, Business Process Automation

Rhia is a Business Process Automation expert and one of the few Nintex virtual Technology Evangelists (vTE) in the world. Her experience defining, implementing, and enhancing processes, governance, and Information Architecture has garnered industry recognition.  Rhia has spoken at industry events throughout Canada and the United States.

SUBSCRIBE TO OUR BLOG

Skyrocket your business with Elantis!

Elantis is your trusted partner in revolutionizing your business operations and taking them to the stratosphere. Our modern solutions support content and collaboration, automation and productivity, governance and compliance, organizational change management, and data analytics—ensuring that your organization stays light-years ahead of the competition.

Ready for lift off? Let’s get started.

RELATED ARTICLES

Discover Real-World Applications for the Power Platform

Discover Real-World Applications for the Power Platform

Are you looking for innovative solutions to streamline operations, enhance productivity, and drive growth? One such solution is the Microsoft Power Platform, which has gained traction across every industry. Often hailed as a game-changer, the Power Platform offers tools that empower organizations to analyze data, automate processes, and easily create custom applications. But beyond the buzzwords and marketing hype, let’s delve deeper into the real-world applications of the Power Platform and explore how it’s revolutionizing business processes across different sectors.

read more