Inbound Action with specific Subject
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-02-2024 03:03 AM
Hello Team,
I have a requirement to create a Inbound email action. My requirement is that subject will contain "
CETARIS MAINTENANCE MICROSOFT: Add PO Number" in which
CETARIS MAINTENANCE will be unique and Microsoft and Add PO Number will need to updated in SC TASK variables.
Problem is, there is already a inbound that creates a ticket when an email is sent to purchasetopaysupport@ubz.com and below is the code
Now there is a new requirement that the team will send email to ServiceNow with this specific subject line "CETARIS MAINTENANCE MICROSOFT: Add PO Number" in which CETARIS MAINTENANCE will be unique and the rest will change and the email will be sent to same email address = purchasetopaysupport@ubz.com
Also when a RITM is created it has a SCTASK so if the subject line contains CETARIS MAINTENANCE then the variables of the SCTASK should automatically update the below values
category should be set to "Customer Service"
inquiry should be set to "MAINTENANCE/CETARIS"
vendor_name should be set to MICROSOFT
provide_details_of_request should be set to Add PO
thanks in advance for your help. I was suggested to create a new inbound for the specific subject line. Any help on this would be appreciated. Thanks!!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-02-2024 04:12 AM
(function runAction(current, event, email, logger, classifier) {
// Check if the subject contains "CETARIS MAINTENANCE" followed by vendor and action
var subjectPattern = /^CETARIS MAINTENANCE (.+): (.+)$/;
var matches = email.subject.toString().match(subjectPattern);
if (matches) {
var vendor_name = matches[1].trim(); // Extract vendor name
var provide_details_of_request = matches[2].trim(); // Extract action
createRequest(vendor_name, provide_details_of_request);
} else {
// Handle other cases or log a message if the subject doesn't match
logger.info("Email subject does not match expected pattern.");
}
function createRequest(vendor_name, provide_details_of_request) {
var user = '';
var gr = new GlideRecord("sys_user");
gr.addActiveQuery();
gr.addQuery("email", 'LIKE', email.from);
gr.query();
if (gr.next()) {
user = gr.getUniqueValue();
} else {
user = '5136503cc611227c0183e96598c4f706'; //guest user
}
var cartId = GlideGuid.generate(null);
var cart = new Cart();
var item = cart.addItem("3b7b5f0c1ba2e150a5acdc66b04bcbcc"); // purchasetopaysupport
cart.setVariable(item, 'requested_for', user);
cart.setVariable(item, 'subject', email.subject.toString());
cart.setVariable(item, 'body', email.body_html);
var rc = cart.placeOrder();
var ritm = new GlideRecord('sc_req_item');
ritm.addQuery('request', rc.sys_id);
ritm.query();
if (ritm.next()) {
GlideSysAttachment.copy('sys_email', event.sys_id, 'sc_req_item', ritm.sys_id);
ritm.requested_for = user;
ritm.u_requested_for = user;
ritm.opened_by = user;
ritm.short_description = email.subject;
ritm.contact_type = 'email';
// Update SCTASK based on the specific subject line
var sctask = new GlideRecord('sc_task');
sctask.addQuery('request_item', ritm.sys_id);
sctask.query();
if (sctask.next()) {
sctask.category = "Customer Service";
sctask.inquiry = "MAINTENANCE/CETARIS";
sctask.vendor_name = vendor_name;
sctask.provide_details_of_request = provide_details_of_request;
sctask.update();
}
ritm.update();
}
}
})(current, event, email, logger, classifier);