Employee Center Pro - Anniversary/Birthday/Announcement

This article explains how to display a static banner with dynamic visibility. The banner will be visible only to certain employees based on their anniversary, birthday, or specific announcements.

Please follow the step-by-step instructions below:

Step 1:
Create a Portal Content like this.

Step 2: 
Create the Scheduled content record from the Related List
Add Content, Page, Widget etc.


Step 3:
We need two scheduled jobs to add and clear the audience.
(Note: I recommend using the Flow Designer for easy future enhancements.)

Scheduled Job 1: Adding Audience Script:

// Get today's details
var gdt = new GlideDateTime();
var today_day = gdt.getDayOfMonthUTC();
var today_month = gdt.getMonthUTC();

// Initialize array to hold users with today's birthday
var birthdayUsers = [];

// Query user profiles with active users and non-empty date of birth
var grSnHrCoreProfile = new GlideRecord('sn_hr_core_profile');
grSnHrCoreProfile.addEncodedQuery('user.active=true^date_of_birthISNOTEMPTY');
grSnHrCoreProfile.query();
while (grSnHrCoreProfile.next()) {
// Check if date of birth exists
if(grSnHrCoreProfile.getValue('date_of_birth')) {
var dob = new GlideDateTime(grSnHrCoreProfile.getValue('date_of_birth'));
var dob_day = dob.getDayOfMonthUTC();
var dob_month = dob.getMonthUTC();
// Check if the user's birthday is today or has passed this month
if(dob_month == today_month && parseInt(today_day) >= parseInt(dob_day)){
birthdayUsers.push(grSnHrCoreProfile.getValue('user'));
}
}
}

// Update the audience for the Birthday banner if there are users with today's birthday
if(birthdayUsers.length > 0){
var grc = new GlideRecord('sn_cd_content_visibility');
grc.addQuery('sys_id', '####scheduled_content__sys_id#####'); // Update
grc.query();
if(grc.next()){
grc.setValue('active', true);
grc.setValue('audience', '');
grc.setValue('use_adhoc_users', true);
grc.setValue('users', birthdayUsers.join(","));
grc.update();
}
}















Scheduled Job 2: Clearing Audience Script:

// Initialize GlideRecord for content visibility
var grc = new GlideRecord('sn_cd_content_visibility');

// Query the specific record by sys_id
grc.addQuery('sys_id', '####scheduled_content__sys_id#####');
grc.query();

// If the record is found, deactivate it and clear the users field
if (grc.next()) {
grc.setValue('active', false); // Deactivate the record
grc.setValue('users', ''); // Clear the users field
grc.update(); // Update the record
}


















That's it. We are good with configurations; now, we test and debug.