- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hello all,
I have configured a notification on my custom table, with When to run is whenever a record is created.
So, when the user receives email on this, I want to provide him a link to "create an Incident".
So, when the user clicks on it from the email he received, an Incident should be created in Service-now instance.
But before creating an Incident, it should check if the user is Active user in service-now and does he has 'itil' role.
The above condition I have not checked, but I have written an email script like this:
So, can someone help me in achieving this? Validating the email receiving user in Service-now and also create incident when clicked on the link.
Thank you,
Regards,
Lucky
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hi @Lucky1
Try this:
1: Create/update your Mail Script
(function runMailScript(/* Template */ template, /* TemplatePrinter */ email, /* Event */ event, /* Table */ current, /* EmailLog */ log) {
var sysId = current.sys_id;
var tableName = current.getTableName();
var emailUrl = gs.getProperty('glide.servlet.uri') + 'nav_to.do?uri=';
var mailto = "mailto:" + gs.getProperty('glide.email.smtp.from') +
"?subject=Create%20Incident%20from%20" + tableName%20+:%20" + sysId +
"&body=Ref:%20" + sysId;
template.print('<a href="' + mailto + '">Create an Incident</a>');
})(current, template, email, event, current);
2: Create an Inbound Email Action
Go to System Policy > Email > Inbound Actions > click New
- Name: Create Incident from Custom Table Email
- Type: Record Action
- Target Table: Incident [incident]
- Condition: email.subject.indexOf("Create Incident from") > -1
(function runAction() {
var userGr = new GlideRecord('sys_user');
userGr.addQuery('email', email.from);
userGr.query();
if (userGr.next()) {
var isActive = userGr.active == true;
var hasItil = userGr.hasRole('itil');
if (isActive && hasItil) {
current.caller_id = userGr.sys_id;
current.short_description = email.subject;
current.description = email.body.text;
current.insert();
} else {
gs.log('User ' + email.from + ' attempted to create incident via email but failed active/itil validation.');
}
} else {
gs.log('Inbound email sender ' + email.from + ' not found in sys_user table.');
}
})();
Regards
Tanushree Maiti
ServiceNow Technical Architect
LinkedIn: https://www.linkedin.com/in/tanushreemaiti
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 weeks ago
Hi @Lucky1
emailUrl is not variable..
glide.email.smtp.from -- its the sys_property name .
Did you create the sys_properties, if it does not exist. Share the screen shot.
Regards
Tanushree Maiti
ServiceNow Technical Architect
LinkedIn: https://www.linkedin.com/in/tanushreemaiti
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 weeks ago
Hello TanuShree,
Good Morning!!
Actually, I did not understand where we are using 'emailUrl' variable and what is the use of it.
Secondly,
Secondly, as I told you even if the property "glide.servlet.uri" is not available in my instance it is giving my instance url when checked in Scripts Background.
And finally, which property you are asking me to create and what value should be updated in it? And also, can you please tell me why creating a system property is needed here?
Thank you,
Regards,
Lucky
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 weeks ago
Hi @Lucky1
1. For System property "glide.servlet.uri". Do not override. Refer: Demystifying glide.servlet.uri in ServiceNow
Can you run this 2 lines in your fix script/backgroud script. It is OOB.
var instance = gs.getProperty('glide.servlet.uri');
gs.print(instance);
2. for System property glide.email.smtp.from
- Type sys_properties.List in Navigator
- Create New
- Set proper email id where you want to send the email
Regards
Tanushree Maiti
ServiceNow Technical Architect
LinkedIn: https://www.linkedin.com/in/tanushreemaiti
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 weeks ago - last edited 2 weeks ago
Hello TanuShree,
Yes, when I created that property "glide.email.smtp.from" and in the value I have kept my email address, then when I click on Create Incident, To is popping up with my email address.
But is it really needed to create this property?
Is there any way we can get the email address from the notification "Who will receive" ?
Also, one more thing, the incident is not getting created when I send the email to my email address.
If I am not wrong, I guess we need to give the instance url like dev12345@servicenow.com.
Am I right?
Regards,
Lucky
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 weeks ago
Hello TanuShree,
Good day!!
When I clicked on Create an Incident in the Preview notification, it is opening the mailbox and a new email is popping up. Good as of now.
But when I see the 'To' it is giving null like shown below:
Note:
Even if I don't see the System Property mentioned in the below line, it is giving me my service-now instance URL.
gs.getProperty('glide.servlet.uri');
But the other System property, is giving null.
gs.getProperty('glide.email.smtp.from');
Why?
Could you please help me?
Regards,
Lucky