The CreatorCon Call for Content is officially open! Get started here.

Add view control to My Request Widget

josely
Tera Contributor

Hi, 

 

I have a requirement to add the ability to toggle from card view and list view on the My Request widget. Any tips?viewcontrol.PNG

5 REPLIES 5

Ahana 01
Tera Expert

Sure, here are the steps you can follow to add the ability to toggle between card view and list view on the My Request widget:

1. Open the widget instance that you want to modify in Service Portal.

2. In the Widget Instance form, click on the Widget field to open the widget record.

3. In the Widget form, click on the "Clone" button to create a copy of the widget. This is to ensure that you don't modify the out-of-the-box widget.

4. In the cloned widget, navigate to the HTML Template field. This is where you will add the code to add the toggle button.

5. Add a button or a switch in the HTML Template to serve as the toggle. You can use AngularJS or Bootstrap to create the toggle. Here is a sample code for a simple button:

html
Toggle View


6. In the Client Script field, add a function to handle the toggle. Here is a sample code:

javascript
c.toggleView = function() {
c.data.listView = !c.data.listView;
}


7. In the Server Script field, add a line to initialize the listView variable. Here is a sample code:

javascript
data.listView = true;


8. Now, modify the HTML Template to display the requests in card view or list view based on the listView variable. You can use the ng-show or ng-hide directives to conditionally display the elements. Here is a sample code:

html

 

 

 


9. Save the changes and test the widget in Service Portal.

Please note that this is a simplified example and you might need to adjust the code based on your exact requirements and the structure of the My Request widget.


nowKB.com
For a good and optimistic result, and solving ServiceNow-related issues please visit this website.https://nowkb.com/home

josely
Tera Contributor

Hi, none of the code snippets came through. 

Dr Atul G- LNG
Tera Patron
Tera Patron

Hi 

The code is here, please check and try to add as you need. 

LearnNGrowAtul_0-1705572963616.png

 

*************************************************************************************************************
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]

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

I will reference this widget. I referenced the topics widget but this one looks more simple. thanks