How to separate announcement widgets in the service portal?

fujiwara2
Giga Contributor

I would like to prepare two announcement widgets on the service portal and divide the contents to be displayed according to the contents.
For example, create a category field in the announcements table.
Use this category field to separate announcements.

find_real_file.png

Create the following widget on the service portal.
(Widget that duplicates the announcements widget)
・Operational status
・News
I want the "Operation Status" widget to display only the records whose category is Operation Status, and the "News" widget to display only the records whose category is News.

find_real_file.png

By modifying the Body HTML template and Server script, we were able to separate the widgets into categories.
I just want it to look like the default announcement widget.
※ The summary will be displayed when you click it, etc.
How do I fix the widget?

Below is the content of the modified widget.

â–¼Body HTML template

<div ng-class="['panel', 'panel-{{::c.options.color}}', 'b', 'spw-announcements-root', '{{::c.wid}}', {'accessibility-off': c.accessibilityOff}]">
<div class="panel-heading">
<h3 class="h4 panel-title"><span ng-if="c.options.glyph"><fa name="{{::c.options.glyph}}"/></span>{{::c.options.title}}</h3>
</div>

<div class="list-group">
<a class="list-group-item" ng-repeat="note in data.notes">
<h4 class="list-group-item-heading">
{{note.title}}
</h4>
<p class="list-group-item-text">
{{note.note}}
</p>
</a>
</div>

â–¼Server script

(function() {
options.title = gs.getMessage('{0}', options.title || 'Announcements');
options.max_records = options.max_records ? options.max_records : 20;
options.paginate = options.paginate === 'true' && options.max_records;
options.use_display_style = options.use_display_style === 'true';
data.rowsMessage = gs.getMessage('Rows {0} - {1} of {2}');

if (options.view_all_page) {
var gr = new GlideRecord('sp_page');
gr.get(options.view_all_page);
options.view_all_page = gr.getValue('id');
}

if (options.type) {
var types = [];

options.type.split(',').forEach(function(type) {
var gr = new GlideRecord('announcement_consumer_type');
gr.get(type);
types.push(gr.getDisplayValue('name'));
});

options.type = types.join(',');
}

data.notes = [];
var annGR = new GlideRecord('announcement');
annGR.addQuery('u_category', 'news');
annGR.addQuery('active',true);
annGR.orderByDesc('sys_created_on');
annGR.query();
while (annGR.next()) {
var annObj = {};
//use service portal helper method to get some display values
$sp.getRecordDisplayValues(annObj, annGR, 'number,title,sys_id');
//get the first 20 characters of the description
annObj.note = annGR.getValue('summary');
//push the populated obj into the array
data.notes.push(annObj);
}
})();

1 ACCEPTED SOLUTION

ServiceNow Tec2
Mega Sage
This has been resolved by ServiceNow Technical Support. Please refer to KB0971695 for more information.

View solution in original post

1 REPLY 1

ServiceNow Tec2
Mega Sage
This has been resolved by ServiceNow Technical Support. Please refer to KB0971695 for more information.