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.

1 ACCEPTED SOLUTION

iftekharmir
Tera Guru

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

 

 
 

 

 

View solution in original post

4 REPLIES 4

iftekharmir
Tera Guru

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?

Hi @GeorgeH91311637 ,

Glad it helped! 😊

Yes, you can extend this further to support both requirements.

Filter announcements from the last 12 months

You can add a condition on the 'from' date like below:

 

 
var gdt = new GlideDateTime();
gdt.addMonthsUTC(-12);

gr.addQuery('from', '>=', gdt);

This ensures only inactive announcements that started within the last 12 months are returned.


Include 'from' and 'to' fields in widget data

You can simply include these fields in your response object:

 

 
from: gr.getDisplayValue('from'),
to: gr.getDisplayValue('to')

Updated snippet (for clarity)

 

gr.addQuery('active', false);

var gdt = new GlideDateTime();
gdt.addMonthsUTC(-12);
gr.addQuery('from', '>=', gdt);

gr.orderByDesc('from');

This will give you:
->Inactive announcements
->Only from last 12 months
->With visible “from” and “to” dates


If you found this helpful, please mark it as helpful 🙌

Thank you for all your help, this has been great!