Create and embed a new Widget
In this example, we will create a simple widget that displays a list of high priority incidents. We will embed this widget into a page that we created in the Create a new Page section.
Create a new Widget
To create a new widget, click the Widgets menu item in the left sidebar.
There are three required fields:
- Title: The display name of the widget.
- Type: The type of the widget. For this example, we will select Widget.
- Name: The name of the widget. This will be used as the identifier for the widget therefore it must be unique.
(function (params) {
function initialize() {
var model = {
condition: true,
priority_incidents: []
};
var priorityIncidentsGr = new GlideRecord('incident');
priorityIncidentsGr.addEncodedQuery('active=true^priority=1');
priorityIncidentsGr.query();
while(priorityIncidentsGr.next()){
model.priority_incidents.push({
sys_id: priorityIncidentsGr.getUniqueValue(),
number: priorityIncidentsGr.getValue('number'),
short_description: priorityIncidentsGr.getValue('short_description')
});
}
return model;
}
return {
initialize: initialize
};
})(params);
function execute(helpers){
return {
};
}
<div class="d-flex justify-content-center">
<template x-for="incident in $scope.model.priority_incidents">
<mdui-card variant="filled" class="m-1 p-3" style="width: 200px;height: 124px">
<div class="fw-bold">
<span x-text="incident.number"></span>
</div>
<div>
<span x-text="incident.short_description"></span>
</div>
</mdui-card>
</template>
</div>
Embed the Widget into a Page
To embed the widget into a page, we use the following code below. Note the highlighted line which indicates the html tag with the widget id as the attribute.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
|