Inbound email action help!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
9 hours ago
Hi, I have a requirement that every time an email is received from a specific domain e.g example.com and subject starts with "X" an incident needs to be created.
This is an example of the email body of the email:
UserX - Line 1
EMP-MSC-PBI=001- Employeee acount changes
Power BI Non Live
BI CUS
Power BI
The requirement is that the requestor on the incident should be set to the user in line 1 from the body of the email.
Currently an incident gets created however the requestor is set to the person who sent the email rather than the first line of the email body. How do i go about this?
This is my current script under the actions business rule section of the inbound action:
createSAPIncident();
function createSAPIncident()
{
var sid = gs.createUser(email.from);
current.caller_id = sid;
current.short_description=email.subject;
current.description=email.body_html;
current.assignment_group = gs.getProperty('sn.assignment.group');
current.contact_type = gs.getProperty('sn.inbound.contact.type');
current.u_service = gs.getProperty('sn.inbound.u.service');
current.incident_state = gs.getProperty('sn.inbound.incident.state');
current.category =gs.getProperty('sn.inbound.category');
current.priority = gs.getProperty('sn.inbound.priority');
current.u_alternate_contact_details=gs.getProperty('sn.inbound.u.alternate.contact.detail');
current.subcategory=gs.getProperty('sn.inbound.subcategory');
current.u_resolution_service =gs.getProperty('sn.inbound.u.resolution');
current.insert();
}
How do i modify to set caller_id to first line of email body?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
8 hours ago
Hi @Nabilah!
You are close - You can extract the first line of the email body before creating the record and use that to look up the correct user instead of email.from.
function createSAPIncident() {
// Split email body into lines
var lines = email.body_text.split('\n');
var firstLine = lines[0].trim();
// Look up user record by name or email (depending on your format)
var user = new GlideRecord('sys_user');
if (user.get('name', firstLine)) {
current.caller_id = user.sys_id;
} else {
gs.info('No matching user found for: ' + firstLine);
current.caller_id = gs.createUser(email.from); // fallback
}
If UserX is the email and not their name then replace with: if (user.get('email', firstLine))
Hope this helps!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
8 hours ago
Hi @Nabilah ,
Can you please try below code
createSAPIncident();
function createSAPIncident() {
var sid = gs.createUser(email.from);
var userGR = new GlideRecord('sys_user');
userGR.addQuery('name', sid);
userGR.query();
var callerSysId;
if (userGR.next()) {
callerSysId = userGR.sys_id;
}
current.caller_id = callerSysId;
current.short_description = email.subject;
current.description = email.body_html;
current.assignment_group = gs.getProperty('sn.assignment.group');
current.contact_type = gs.getProperty('sn.inbound.contact.type');
current.u_service = gs.getProperty('sn.inbound.u.service');
current.incident_state = gs.getProperty('sn.inbound.incident.state');
current.category = gs.getProperty('sn.inbound.category');
current.priority = gs.getProperty('sn.inbound.priority');
current.u_alternate_contact_details = gs.getProperty('sn.inbound.u.alternate.contact.detail');
current.subcategory = gs.getProperty('sn.inbound.subcategory');
current.u_resolution_service = gs.getProperty('sn.inbound.u.resolution');
current.insert();
}
Please mark my answer correct and helpful if this works for you
Thanks and Regards,
Sarthak