How to Send iCalendar attachments from Service Now in Email Notifications. #ical #vcal #outllook meeting invites
Hi Folks,
This article explains how to generate iCalendar attachments in Service Now and send it over as an attachment in email notifications. I came across this requirement and could find any solution over the internet, so I decided to build my own solution.
The actions begins below.....
iCalendar attachments are basically outlook meeting invites attachment that contains details for meeting such as "Meeting Start Date Time", "Meeting End Date Time", "Meeting URL for Joining meeting", "Location" , "Description", etc.
Below is the screenshot of the icalendar attachment in an Email.
When the attachment is opened it contains meeting details as shown below.
I am able to generate the ICS attachment using a script include. I am also maintaining a table that contains the meeting the details specific for the meeting. The snapshot of a record in the table along with the generated attachment is below.
The Script that generates the attachment is below
var ICS_SNOW_AttachmentGenerator = Class.create();
ICS_SNOW_AttachmentGenerator.prototype = {
initialize: function() {
},
_formatDate: function(dateunformatted){
var formDate = dateunformatted+"";
formDate = formDate.replace(/\-/g,"");
formDate = formDate.replace(/\s+/g,"T");
formDate = formDate.replace(/\:/g,"");
formDate = formDate + "Z";
return formDate;
},
/*
GRObj is the GlideRecord Object of the record in my custom table containing the details of the meeting.
*/
payloadGen: function(GRObj){
var startDate = this._formatDate(GRObj.meeting_start_date_time);
var endDate = this._formatDate(GRObj.meeting_end_date_time);
var payload = "";
payload += "BEGIN:VCALENDAR\r\n";
payload += "VERSION:2.0\r\n";
payload += "PRODID:-//Service-now.com//Outlook 11.0 MIMEDIR//EN\r\n";
payload += "METHOD:REQUEST\r\n";
payload += "BEGIN:VEVENT\r\n";
var attendees = GRObj.meeting_attendees;
var attendees_list = attendees.split(',');
if(attendees_list.length > 0){
for(var i = 0; i < attendees_list.length; i++){
payload += "ATTENDEE;ROLE=REQ-PARTICIPANT;RSVP=TRUE:MAILTO:" + attendees_list[i] + "\r\n";
}
}
payload += "ORGANIZER:MAILTO:teamXYZ@example.com" + "\r\n"; // The ORGANISER tag is generally used to override the email address where the responses will be send, when replied by the attendees for the invites received by them. Moreover, if the value of ORGANISER tag is set then the recipients will receive mails fromm the value mentioned in the organizer tag.
payload += "DTSTART:" + startDate + "\r\n";
payload += "DTEND:" + endDate + "\r\n";
payload += "LOCATION:India VRoom" + "\r\n"; // you can use variable, if you are maintaining VRooms for your meetings;
payload += "TRANSP:OPAQUE" + "\r\n";
payload += "UID:" + new GlideEmailWatermark().optionallyRandomize(GRObj.u_number) + "\r\n";
payload += "DTSTAMP:" + this._formatDate(new GlideDateTime().getValue()) + "\r\n";
payload += "DESCRIPTION:You are requested to join the meeting for the discussion of XYZ Request\r\n"; //provide your own mwssage or populate using variables.
payload += "SUMMARY:Meeting Invite for XYZ Request\r\n";
payload += "PRIORITY:5\r\n"; // can take values from 0 to 9 "0 to 4 HIGH Priority, 5 MODERATE PRIORITY, 6 to 10 LOW PRIORITY".
payload += "X-MICROSOFT-CDO-IMPORTANCE:1\r\n"; //can take values from 0 to 2. Specifies the importance of an appointment.
payload += "CLASS:PUBLIC\r\n";
payload += "BEGIN:VALARM\r\n";
var alarm_time = 10;
payload += "TRIGGER:-PT" + alarm_time +"M\r\n"; // The TRIGGER take values in MINUTES and the VALARM EEVENT triggers a reminder message on the recipients screen 10 minutes before meeting start.
payload += "ACTION:DISPLAY\r\n";
payload += "DESCRIPTION:Reminder\r\nEND:VALARM\r\nEND:VEVENT\r\nEND:VCALENDAR\r\n";
gs.info(payload);
var gAttach = new GlideSysAttachment();
gAttach.write(GRObj, "Meeting_Invite[" + new GlideDateTime().getValue() + "].ics", 'text/calendar', payload);
},
type: 'ICS_SNOW_AttachmentGenerator'
};
Once the attachment is generated and attached to your meeting record the road is simple and easy. In order to send the attachment on an email, go to Notification Module > Create a Notification and in "What it will Contain" tab, check the "Include Attachment" checkbox. Show your creativity in HTML box for your email and give it a personalize touch.Enjoy....
This solution doesn't make use of Service Now ICS field maps templates and being restricted to plain text only. It allows you to freely include HTML in your meeting invites and build your custom meeting invites attachments.
https://www.servicenow.com/community/now-platform-articles/how-to-send-icalendar-attachments-from-service-now-in-email/ta-p/2326291
