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);

            }
        }

    }

})();



11 REPLIES 11

@PRAVALIKAREDDYL 

share how are you adding user criteria for announcement? share screenshots

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

I am sharing the announcement record screenshot Where i have added the user criteria under can view.

@PRAVALIKAREDDYL 

surprisingly I couldn't see both the related list on form even after adding that system property

share screenshot of that user criteria where you applied that script

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

we are using custom widget to get the announcements to display on the portal.
server script of the widget: 

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);

            }
        }

    }

})();

@PRAVALIKAREDDYL 

why widget script is written for handling announcement?

you already have user criteria to show/hide

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