- 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
3 weeks ago
not a good practice to insert record from email script
Let them reply to that email and you can configure inbound action to create INC
OR
Have a link to portal where they can raise incident
💡 If my response helped, please mark it as correct ✅ and close the thread 🔒— this helps future readers find the solution faster! 🙏
Ankur
✨ Certified Technical Architect || ✨ 10x ServiceNow MVP || ✨ ServiceNow Community Leader
- 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
3 weeks ago - last edited 3 weeks ago
Hi Tanushree,
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;
Also, where does this variable used? emailUrl
From these two lines, I don't see the property in system properties.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hi @Lucky1
Just create the sys_properties , put an email id in the value where email will be sent and you can test in non-prod .
You will give sys_properties name as per your choice like glide.email.to
Let me know whether you are getting expected your result
Regards
Tanushree Maiti
ServiceNow Technical Architect
LinkedIn: https://www.linkedin.com/in/tanushreemaiti