Is there any way to process an email script in meeting invitation email template?

Aanchal Mehndi1
Giga Contributor

Is there any way to process an email script in meeting invitation email template? As per the service now, email script is not allowed in meeting invitation email template.

I have done calendar integration for change_task. So, i used an email template to send an invite but I also want to send a one hyperlink for which we have written mail script under body of the message in other notifications. But for calendar invitations, how should i send that hyperlink????Email_template.PNGmail_script.PNG

11 REPLIES 11

Hi Mike,



Will this send an Mail Script part(Hyper Link in my case) in the meeting invitation email itself?


I want to send it out in the meeting invitation email itself.



Actually along with the meeting invite, we need to send additional info & hyper-links in the same email So i added that content in the message field and description field in the calendar is fetching that info coz description field in calendar is mapped with the body content of the email.But it is not processing the hyper Link, instead showing up the whole code in the tag.Please see below screenshot.



email template1.PNG



Regards,


Aanchal


I see. If you use the approach I'm suggesting it should give you access to the raw message that is constructed after the Notification and Template is processed, because you are intercepting it via the sys_email table prior to the email being sent. You should have access to the raw message text, which you can then update via a Business Rule, wherein which your custom code can run. You will likely have to use the XML Helper or XML Document parsing to update this. I don't know if there is an easier way, but I believe this approach will work. Here is some code that conveys the general idea. The code is not complete and likely not targeting the table you care about. This could be a before insert/update or after insert/update business rule perhaps, the key is to check that the current.body field has a value in it before manually trying to manipulate it.



if (current.type == 'send-ready' && current.subject == 'My Calandar Notification Subject') {
      if (!current.body.isNil()) {
              updateMessage();
      }
}


function updateMessage() {
      var currentMessageBody = String(current.body);
      var serverLink = 'https://' + String(gs.getProperty("instance_name")) + '/change_request.do?sys_id=';
      var recordSid = String(current.instance);
      var messageToPrepend = 'To view the Change Task in the ... application: ' + '<a href="' + serverLink + recordSid + '">,/a>';
      var newMessageBody = "";
      // IF sys_email body was text only, you would simply prepend the message to the body content, but because this is a hyperlink you'll likely


      // Need to use the xml parsing approach
      if (currentMessageBody.indexOf("<html>") == -1) {
              newMessageBody = messageToPrepend + currentMessageBody;
      }


      // IF sys_email body is HTML use XML Document parser or the XML helper to add messageToPrepend as a new element to the document body


    // Refer to XMLDocument Script Object - ServiceNow Wiki
      /*
      var xmldoc = new XMLDocument(currentMessageBody);
      var bodyNode = xmldoc.getNode("/html/head/body");
      xmldoc.setCurrent(bodyNode);
      xmldoc.createElement("p", messageToPrepend);
      */
      current.body = newMessageBody;
}




Mike