Show Inactive Announcments for last 12 months in Service Portal Widget

GeorgeH91311637
Tera Contributor

I have a client that is wanting to have a separate widget underneath the OOTB Announcements widget, to show all historical inactive announcements that have been published for a specific portal.

 

I have taken a clone of the OOTB Announcements Widget, updated the title etc, but for the life of me I cannot figure out how to update the widget code or function that provides the widget with the data, so that I can display inactive announcements for the last 12 months for this client.

Any guidance/advice would be fantastic.

2 REPLIES 2

iftekharmir
Tera Contributor

Hi @GeorgeH91311637 ,
The  OOTB Announcements widget does not fetch data from its server script.

It uses the spAnnouncement Angular service in the client script:

spAnnouncement.get(...)

This service only returns active announcements, which is why modifying the widget server script doesn’t change the data.


Solution: Replace spAnnouncement with a custom GlideRecord query

To show inactive announcements, you need to bypass spAnnouncement and fetch data directly from the server.


🔧 Server Script (Fetch inactive announcements)

(function() {

    data.announcements = [];

    var gr = new GlideRecord('announcement'); // confirm table if needed
    gr.addQuery('active', false); // fetch inactive only
    gr.orderByDesc('sys_updated_on');
    gr.query();

    while (gr.next()) {
        data.announcements.push({
            id: gr.getUniqueValue(),
            title: gr.getDisplayValue('title'),
            summary: gr.getDisplayValue('summary'),
            targetLink: gr.getValue('url'),
            targetLinkText: gr.getDisplayValue('url_target'),
            clickTarget: gr.getValue('click_target')
        });
    }

})();

🔧 Client Script (Remove spAnnouncement usage)

Replace the existing data fetch logic with:

function($scope, spAriaUtil) {

    var c = this;

    c.wid = 'spw-announcements-' + new Date().getTime();
    c.accessibilityOff = spAriaUtil.g_accessibility === 'false';

    c.announcements = c.data.announcements || [];
    c.totalAnnouncements = c.announcements.length;

    c.announcements.forEach(function(a) {
        a.canExpand = a.summary || a.targetLinkText;
        a.expanded = false;
    });

    c.toggleDetails = function(announcement) {
        announcement.expanded = !announcement.expanded;
    };

    c.linkSetup = function(a) {
        a.linkTarget = '_self';

        if (a.clickTarget === 'urlNew')
            a.linkTarget = '_blank';

        a.linkType = !a.targetLink ? 'none' : a.targetLinkText ? 'normal' : 'title';
    };

}
 

Result

This will display all inactive (historical) announcements while keeping the same UI and behavior as the original widget.

 

Screenshot 2026-03-27 at 7.11.16 PM.png


If you found this uelpful, please mark it as helpful.
Regards,
Iftekhar

 

 
 

 

 

This is absolutely fantastic thank you.
Would you be able to help support with additional check for 'from' date being in the last 12 months.

Also is it possible to include the 'from' and 'to' fields in the widget data?