How can I add a search bar within my SP widget?

Bushra Syed
Tera Contributor

I have a service portal widget that is a sidebar for my custom Service Portal and I want to add a typeahead search into it. Currently, I have code like this:
HTML:

 

 

<div>
  <div>
<sp-widget widget="data.example"></sp-widget>
  </div>
</div>

 

 

 

SERVER:

 

 

 data.example = $sp.getWidget('typeahead_search', {});

 

 

This doesn't work 

 

"$sp is not defined".  

Is there any way to do this?

3 REPLIES 3

Dr Atul G- LNG
Tera Patron
Tera Patron

Hi @Bushra Syed 

 

Please provide screen shot where you want to add?

*************************************************************************************************************
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.

Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]

****************************************************************************************************************

It is within a custom widget I made. 

ChrisBurks
Mega Sage

Hi @Bushra Syed ,

If you're using a portal widget your code should be good the way it is except for the widget id for the typeahead search. The id for that widget has a hyphen and not an underscore.

Using the widget editor with preview on, the screenshoot below shows the code working.

portal_widget_with_embedded_search.png