- Post History
- Subscribe to RSS Feed
- Mark as New
- Mark as Read
- Bookmark
- Subscribe
- Printer Friendly Page
- Report Inappropriate Content
on 12-18-2018 10:05 AM
Hello,
This series of articles will help you understand what in Service Portal and how the pages and widgets are related to the Service Portal.
What does a Widget mean in Service Portal ?
Widgets are reusable components which make up the functionality of a portal page. Widgets are what define the content in your portal. Widgets define what a portal does and what information a user sees
Four main aspects of the Widgets
The main aspects and on which Widget is reliable,
1) HTML Template (A mandatory widget component)
The HTML template requires knowledge of AngularJS to display and gather data. Use the HTML template to:
- Render the dynamic view that a user sees in the browser using information from the model and controller.
- Bind client script variables to your markup.
- Gather data from the end user.
2) Client Script (A mandatory widget component.)
A client script requires knowledge of both the ServiceNow API and AngularJS to create a client controller. Use the client script to:
- Map server data from JavaScript and JSON objects to client objects.
- Process data before rendering it.
- Pass data to the HTML template.
- Pass user input and data back to the server for processing.
3) Server Script (A mandatory widget component.)
A server script requires knowledge of the ServiceNow API to work with record data. Use the server script to:
- Set the initial state of the widget.
- Send record data to the widget client script using the data variable.
- Run server-side queries.
4) CSS/SCSS (A mandatory widget component.)
Things to know before starting to build a Widget
To develop widgets, you need ServiceNow API experience to:
- Run record queries on the server.
- Create and update records.
You need AngularJS experience to:
- Bind variables to client controllers.
- Access server objects in a widget.
- Gather user input.
Add a widget to a Page
Global Objects available in Widget
When a widget begins to render for the first time on a page, the server script executes first and accesses three global objects: input, options, and data. Because the input variable is a data object sent from the client script, this variable is undefined when first initialized.
When a widget is first instantiated, the server script:
- Initializes an empty data object.
- Initializes the input object with any data sent from the client controller, or the options object with any data used to initialize the widget.
- Sends the data object to the client controller as JSON.
The client script:
-
Accesses the server data object using c.data.Widget use c variable to represent controller.
-
Uses sever.update() to post changes to the data model. This method updates the server script using the input object. Calling
server.update()
, the client script data object is automatically overwritten by the server script data object. - Uses c.options to access the values used to invoke the widget on the server. This object is read-only.
Embed a Widget
You can embed a Widget in HTML template, Client script and Server side
Embed a widget in an HTML template
<div>
<widget id="widget-cool-clock"></widget>
</div>
<widget id="widget-cool-clock" options='{"zone": "America/Los_Angeles","title": "San Diego, CA"}'></widget>
- HTML template
-
<widget id="widget-cool-clock" options='data.clockOptions'></widget>
- Server script
-
(function() { data.clockOptions = {"zone": "America/Los_Angeles","title": "San Diego, CA"}; })();
Embed a widget in a client script
spUtil.get("widget-sc-cat-item", {sys_id: "your_catalog_item_sys_id"}).then(function(response) {
c.catalogItemWidget = response;
});
When using the spUtil class in a widget client script, you must inject the class into the client script function. The following example embeds the Cool Clock widget:
- Client script
-
function(spUtil) { var c = this; spUtil.get("widget-cool-clock").then(function(response) { c.myClockWidget = response; }); }
- HTML template
-
<sp-widget widget="c.myClockWidget"></sp-widget>
Embed a widget in a server script
data.catalogItemWidget = $sp.getWidget("widget-sc-cat-item");
The following example embeds the Cool Clock widget:
- Server script
-
(function() { var coolClockOptions = {"zone": "America/Los_Angeles","title": "San Diego, CA"} data.coolClockWidget = $sp.getWidget('widget-cool-clock', coolClockOptions); })();
- HTML template
-
<sp-widget widget="data.coolClockWidget"></sp-widget>
Thanks & Regards,
Ashwini
- 2,020 Views
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Link provided doesn't have information now. Please update the article link.