Restrict visibility announcement on portal to specific groups.

PRAVALIKAREDDYL
Tera Contributor

Hi,

I have a requirement to restrict the visibility of an announcement tile on the portal so that only members of specific groups can see it.

What I have done so far:

  • Unchecked the Public option on the announcement
  • Added User Criteria under Can View
  • In the User Criteria, I specified the required groups and saved it

Issue:

Even though I am not a member of those groups, I am still able to see the announcement tile on the portal.

Additional details:

  • The announcement is being fetched and displayed using a custom widget
  • I suspect the User Criteria may not be getting evaluated properly at the widget level

Questions:

Why am I still able to see the announcement even though I don’t meet the User Criteria?

Does User Criteria automatically get enforced when announcements are fetched via a custom widget?

Do we need to explicitly evaluate User Criteria in the widget server script to restrict visibility?

If yes, what is the recommended way to evaluate User Criteria or group membership in the widget?

I am sharing the widget code below for reference.

Any guidance or best practices on implementing this requirement would be really helpful.

Thank you!


CODE:

(function() {
    data.resources = [];
    var grType = new GlideRecord('announcement_consumer_type');
    grType.addQuery('sys_id', options.announcement_type);
    grType.query();
    if (grType.next()) {

        var grAnnouncement = new GlideRecord('announcement');
        grAnnouncement.addQuery('active', true);
        grAnnouncement.addEncodedQuery('typeLIKE' + grType.sys_id);
        grAnnouncement.addEncodedQuery('from<=javascript&colon;gs.endOfToday()^to>=javascript&colon;gs.beginningOfToday()^ORtoISEMPTY');
        grAnnouncement.orderBy('u_order_by');
        grAnnouncement.query();
        while (grAnnouncement.next()) {
  
            if (grAnnouncement['public'] || gs.hasRole(grAnnouncement.roles)) {
                var resource = {};
                resource.hide_on_mobile = grAnnouncement.getValue('u_hide_on_mobile'); 
                $sp.getRecordDisplayValues(resource, grAnnouncement, 'name,title,summary,glyph,click_target,details_url,details_page,u_image_url');
                resource.isMobile = true
                data.resources.push(resource);

            }
        }

    }

})();



4 REPLIES 4

Anurag Tripathi
Mega Patron
Mega Patron

Hi,

 

Have you done this?

 

AnuragTripathi_0-1767353632931.png

 

Source: Set the user criteria for Service Portal system property

-Anurag

Thanks for the quick response. I have checked "yes" for this property , but still i am seeing the announcement in the portal.

Ankur Bawiskar
Tera Patron
Tera Patron

@PRAVALIKAREDDYL 

refer below links for help

Trying to edit User Criteria for SP Announcements, pages, and widgets.

How can we display announcement based on user location

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Thanks for responding, i have tried the things its not working. Even though the set the system property to true and cleared the cache and tested. i am still seeing the announcement on the portal. 
i want to ask whether is it because of the custom widget that fetching the announcement , the widget server script it only evaluating the public and roles not the user criteria.