- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-03-2023 01:29 AM
We have a requirement to sent email to requester's manager for certain tasks.
We have created a scheduled job for this.
How we can pass user name, manager name, manager email address via scheduled job using gs.eventQueue() to the notification.
We have to send notification to requeter's manager and in notification we have to put requester's name and manager name.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-03-2023 01:35 AM - edited 05-03-2023 01:38 AM
Hi,
You can pass it as one of the 2 parameters
gs.eventQueue('<Event Name>', <object of record like Current or Glide Object>, <Param 1>, <Param 2>);
In param one or param 2 you can pass the manager like current.caller_id.manager & in your notification you will have to check the box 'send to param 1' and 'send to param 2' in the who will receive tab
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-03-2023 02:55 AM
You can add the field on notification body as
${u_client_id}
OR
${u_client_id.manager}
You can use dot walk to feel free to go to name or first name as neeed.
You can also choose the fields (and dot walk) from the right pane as below
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-03-2023 07:19 AM
Thank you, Anurag.
We are able to achieve expected functionality. Thank you for your help.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-03-2023 02:08 AM
HI @Nikita Ms ,
I trust you are doing fine.
To send an email notification to a requester's manager for certain tasks, you can create a scheduled job that retrieves the necessary information and uses the gs.eventQueue() function to send the notification.
Here's an example code snippet to demonstrate how this can be achieved:
// Get the current user's record
var currentUser = gs.getUser();
// Get the requester's record for the current task
var requester = current.getValue('requested_for');
// Get the requester's manager's record
var manager = requester.manager;
// Get the email address of the manager
var managerEmail = manager.email;
// Get the names of the requester and the manager
var requesterName = requester.getDisplayValue();
var managerName = manager.getDisplayValue();
// Construct the email notification
var email = new GlideRecord('sys_email');
email.initialize();
email.addRecipient(managerEmail);
email.setSubject('Notification for task ' + current.number);
email.setBody('Dear ' + managerName + ',\n\nThis is to inform you that ' + requesterName + ' has requested a task that requires your approval.\n\nPlease take necessary actions.\n\nThank you,\nServiceNow');
// Queue the email notification for sending
gs.eventQueue('email.send', email, currentUser.getID(), 60);
Was this answer helpful?
Please consider marking it correct or helpful.
Your feedback helps us improve!
Thank you!
Regards,
Amit Gujrathi