Email Script to link the record to backend

Sathiskumar_D
Giga Sage

Hello ,

 

I have a mail script for customer service(sn_customerservice_case). I want to include a link to the record "backend" whenever a customer is attaching a document on the service portal ticket.

i have lots of questions on ${URI} and ${URI_REF} with LINK word to it.I am not sure how to implement it.My code is very generic and i am not sure how to modify this to get the correct record in the backend.Please help me in fixing this error.

 

var gr = new GlideRecord("sys_attachment");
    gr.addQuery('table_name', 'sn_customerservice_case');
    gr.query();
    while (gr.next()) {
       
        template.print('Attachment: <a href="https//' + gs.getProperty("glide.servlet.uri") + '/sys_attachment.do?sys_id=' + gr.sys_id + '">' + gr.file_name + '</a>');
    }
1 ACCEPTED SOLUTION

Hi, it would have been helpful if you had earlier provided clear details regarding any customization that was preventing OOB functionality from working .
What exactly does 'they have hard-coded servicenow instance' mean?

 

Creating a URL for direct access to an instance record via mail script would look something like

var instanceURL = gs.getProperty('glide.servlet.uri');
var myTable = current.sys_class_name;
    
var myURL = '<a href=' + instanceURL + '/nav_to.do?uri=' + myTable + '.do?sys_id=' + current.sys_id + '>' + current.number'</a>';

template.print(myURL);

 

if you are unsure of URL format on any form record header,
you can right click and select 'Copy URL' from the menu.

 

 

View solution in original post

7 REPLIES 7

Tony Chatfield1
Kilo Patron

Hi, based on the code snippet you are trying to include an attachement link in an email?

Who receives the email with the link?
I would think the submitter already has the attachment so does not need another copy
and the attachment is available to logged in resolvers when they access the task to assess the requirements and\or recent update.

Any user would also need to be authenticated to the instance before they could open the URL

Can you clarify the business drivers\use case.

 

 

 

 

I tried to use {URI} and {URI_REF}.Both of them failed. Whenever a customer upload an document, it is supposed to trigger an email to the approver and link to the case record.

Hi, I believe you need a slightly different approach.
Looking at an OOB dev instance, when an attachment is added to sn_customerservice_case a sysevent 'attachment.uploaded' is generated.
You should be able to configure a notification on 'customerservice_case', triggered by this event and use the standard ${URI_REF} or ${URI} within the notification.

You would then need add a mail_script to the message to set the recipents.
So in the mail_script you will need to query ‘sysapproval_approver’ table for your tasks approver(s) and then set the message recipient(s) as the email address of the approver(s)

But be aware that if a user uploads multiple attachments,
the result will be multiple messages and these may be seen as spam by the recipient of the emails.

 

query 'sysapproval_approver' for your task
push the resulting user sys_id’s into an array

query sys_user
iterate through the (approval) user array and push the user email addresses to a new array
Set the new array as To or CC field.

If you have any issues, post you code here and I'm happy to review.

Hi Tony,

 

they have hard-coded servicenow instance. So {URI} and {URI_REF} is not generating a link for any specific record.I just discussed with an architect for this project as well. I will work on your suggestion and post the code for review.