Notification help

SnowDevOps
Giga Guru

Hello

I have 2 custom tables One is courses and the other is called enrollment. I build the workflow to schedule job to send out a notification reminder 2 days before class starts. I'm able to send out the notification to the teacher that they owned from the course table. But i don't know how to send out notification to the students who enroll in the courses. Because each courses has different date, number of students and different teacher names. Any suggestion or ideas. Appreciated ! Thanks 

 

Class A                           Class B                           Class C

teacher John                  teacher Smith                teacher Mike

10 students                     5 students                     8 students

 

1 ACCEPTED SOLUTION

Maddysunil
Kilo Sage

@SnowDevOps 

I think, To send notifications to students enrolled in each course two days before the class starts, you'll need to design a process that iterates through each course record, checks its start date, retrieves enrolled students, and sends notifications to them...means Set up a scheduled job that runs daily to check for courses starting within two days and trigger an event to send notification..below is the sample code

 

 

// Query courses starting within two days
var coursesGr = new GlideRecord('courses');
coursesGr.addQuery('start_date', '>=', gs.daysAgo(2)); // Courses starting within two days
coursesGr.addQuery('start_date', '<=', gs.daysAgo(1)); // Courses starting after two days
coursesGr.query();

while (coursesGr.next()) {
    var courseName = coursesGr.getValue('name');
    var teacher = coursesGr.getValue('teacher');
    
    // Query enrollment for this course
    var enrollmentGr = new GlideRecord('enrollment');
    enrollmentGr.addQuery('course', coursesGr.getUniqueValue()); // Link to the course
    enrollmentGr.query();
    
    while (enrollmentGr.next()) {
        var studentName = enrollmentGr.getValue('student');
        var email = enrollmentGr.getValue('student_email');
        
        // Queue the event to send notification to student
        gs.eventQueue('notification.student.reminder', null, email); // modify as per your event
    }
}

 

Please Mark Correct if this solves your query and also mark 👍Helpful if you find my response worthy based on the impact.

 

Thanks

 

View solution in original post

6 REPLIES 6

Where do you write these script? Would that be schedule job script? I built this flow in Flow Designer. The notification that i have, it works for the teacher. I wonder if i can use the mail scrip then add on notification to do the query or i can add the script above to flow designer. 

SnowDevOps_1-1714027721727.png

 

 

That was great guide. Base on the code, i'm able to translate that into Flow designer.