Hide Category Widget Initially on ESC KB Page, Show After Knowledge Base Selection?

Rahuf Sayyad
Tera Contributor

Hi Community,

I’m working on customizing the **ESC Service Portal Knowledge Base page (`kb_view2`)** in ServiceNow.

**Requirement:**

* When the user clicks **“I want to know something”** and lands on the KB page (`kb_view2`), the **category widget (or category section)** should be **hidden initially**.
* The category section should only **become visible after the user selects a knowledge base**.
* The category widget I want to hide initially has this unique element ID: `kb_categories_title` (or alternatively, a container element with XPath: `//*[@id="xc250b070d7201200a9addd173e24d4a2"]/nav/div`).

---

**What I tried so far:**

* I created a **UI Script** to hide the category widget by setting `display: none` on the element.
* The script works perfectly when I run the hiding code manually in the browser console.
* However, when I add the code to a UI Script and include it in the portal theme, the widget still shows on initial page load.
* I suspect the widget loads asynchronously after the script runs, so my code hides nothing because the element is not present yet.

---

**My current approach:**

I’m using a polling function in my UI Script to check every 500ms for the element and hide it once it appears, stopping after 5 seconds.

---

**Questions:**

1. Is there a better or recommended way to hide a widget or DOM element **on initial load** in Service Portal when the widget loads asynchronously?
2. Is it possible to control the visibility of this category widget via widget options or configuration instead of client scripts?
3. Could cloning and modifying the **KB Categories - KBv3** widget be a better approach?
4. Any best practices on where/how to place such UI Scripts for portal pages (global scope vs scoped app)?

---

Thanks in advance for any guidance or examples!

0 REPLIES 0