- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-27-2023 04:52 AM
Hi,
I need to send weekly notification to assessor with the link whatever the assessment is pending for them.
Table -> asmt_assessment_instance (Assessment Instances)
I am not getting the point how can I send only one email to suer when multiple assessment is assigned to assignee.
For Ex. User A has 10 assessment in pending then only one email should trigger to assessor and link of all 10 assessment need to share with user.
Thanks,
Mukul
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-27-2023 06:19 AM
Please follow the below Steps :
Step 1 : Create event registry (sysevent_register) table to trigger the notification
It will be used in Scheduled job
Step 2 : Create a Scheduled job to send a notification
/*1. Declare array to store assigned to values */
var assignedArray = [];
var unique = [];
/*2. Glide record on assesment table*/
var grAssessor = new GlideRecord('asmt_assessment_instance');
grAssessor.addQuery('state', 'pending'); //use backend value of pending
grAssessor.query();
while (grAssessor.next()) {
/*3. Add the assigned to values in array */
assignedArray.push(grAssessor.getValue('user'));
}
/*
4. Now we have array of assigned to but it may contain duplicate value
so we need to remove duplicate from array
*/
for (i = 0; i < assignedArray.length; i++) {
if (unique.indexOf(assignedArray[i]) === -1) {
unique.push(assignedArray[i]);
}
}
/*5. Loop through Unique array to send notification to user */
for (i = 0; i < unique.length; i++) {
//gs.eventQueue('<event_name_created_in_step1>',object,'parm1','parm2');
gs.eventQueue('asmt.assesment.instance',grAssessor,unique[i]); //will send user in parm1
}
Step 4 : Create email script to show the link (list of records assigned to particular user)
Name : link_to_assesment
function runMailScript(/* GlideRecord */ current, /* TemplatePrinter */ template,
/* Optional EmailOutbound */ email, /* Optional GlideRecord */ email_action,
/* Optional GlideRecord */ event) {
/* Get assigned to from event's parm1 */
var assigned_to = event.parm1;
template.print('<a href=' + gs.getProperty('glide.servlet.uri') + 'asmt_assessment_instance_list.do?sysparm_query=state=pending^user=' + assigned_to + '>' + 'Link' + '</a>');
})(current, template, email, email_action, event);
Step 5 : Create Notification on "asmt_assessment_instance" table , with following configuration
When to send
Send When : Event is fired
Event name : Event created in step 1
What it will contain :
Call mail script created in Step 4
${mail_script:link_to_assesment}
Hope this helps...!!!
ServiceNow Developer
I know one thing, and that is that I know nothing.
- Socrates
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-27-2023 06:19 AM
Please follow the below Steps :
Step 1 : Create event registry (sysevent_register) table to trigger the notification
It will be used in Scheduled job
Step 2 : Create a Scheduled job to send a notification
/*1. Declare array to store assigned to values */
var assignedArray = [];
var unique = [];
/*2. Glide record on assesment table*/
var grAssessor = new GlideRecord('asmt_assessment_instance');
grAssessor.addQuery('state', 'pending'); //use backend value of pending
grAssessor.query();
while (grAssessor.next()) {
/*3. Add the assigned to values in array */
assignedArray.push(grAssessor.getValue('user'));
}
/*
4. Now we have array of assigned to but it may contain duplicate value
so we need to remove duplicate from array
*/
for (i = 0; i < assignedArray.length; i++) {
if (unique.indexOf(assignedArray[i]) === -1) {
unique.push(assignedArray[i]);
}
}
/*5. Loop through Unique array to send notification to user */
for (i = 0; i < unique.length; i++) {
//gs.eventQueue('<event_name_created_in_step1>',object,'parm1','parm2');
gs.eventQueue('asmt.assesment.instance',grAssessor,unique[i]); //will send user in parm1
}
Step 4 : Create email script to show the link (list of records assigned to particular user)
Name : link_to_assesment
function runMailScript(/* GlideRecord */ current, /* TemplatePrinter */ template,
/* Optional EmailOutbound */ email, /* Optional GlideRecord */ email_action,
/* Optional GlideRecord */ event) {
/* Get assigned to from event's parm1 */
var assigned_to = event.parm1;
template.print('<a href=' + gs.getProperty('glide.servlet.uri') + 'asmt_assessment_instance_list.do?sysparm_query=state=pending^user=' + assigned_to + '>' + 'Link' + '</a>');
})(current, template, email, email_action, event);
Step 5 : Create Notification on "asmt_assessment_instance" table , with following configuration
When to send
Send When : Event is fired
Event name : Event created in step 1
What it will contain :
Call mail script created in Step 4
${mail_script:link_to_assesment}
Hope this helps...!!!
ServiceNow Developer
I know one thing, and that is that I know nothing.
- Socrates
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-05-2023 01:01 AM
Provided solution works for me.
Thanks a lot for your quick and descriptive solution.
Thanks,
Mukul
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-03-2025 05:32 AM
Hello Vishal
Thank You, it works for me.!