Populate CI Name in Configuration Item field from email received in SNOW

SNOW46
Tera Contributor

Hello Team,

Currently, we have configured an Inbound Action for Incident Ticket creation for all emails received from a specific email id and when the Subject contains "Resolution state: New".

Below is the Inbound Script.

(function runAction( /*GlideRecord*/ current, /*GlideRecord*/ event, /*EmailWrapper*/ email, /*ScopedEmailLogger*/ logger, /*EmailClassifier*/ classifier) {
gs.include('validators'); {
var fromaddress = email.origemail;
var severity = email.body.severity;
var pri = email.body.priority;
var ci = email.body.path;
//gs.logs("Severity= " +severity+ "\n Priority= "+pri);
// current.comments="Severity: "+severity+"\n Priority:" +pri;
current.comments = "received from: " + email.origemail + "\n\n" + email.body_text;
current.description = email.body_text;
current.short_description = email.subject + " - " + ci;
current.incident_state = 1; //Incident state = New
current.state = 1;
current.contact_type = "Alert";
current.assignment_group = 'a7d3b8241b7ab49040d9eb97624bcb01'; //Assignment Group: ALM-SRM Grp
current.category = "server";
current.subcategory = "SCOM";
current.incident_state = 1;
current.caller_id = 'e21259021b5d85507f0132e2cd4bcbd4';
current.opened_by = 'e21259021b5d85507f0132e2cd4bcbd4';

if (severity == 2 && pri == 2) { // P3 - Medium
current.urgency = 2;
current.impact = 2;
} else { //P4 - Low
current.urgency = 3;
current.impact = 3;
}

current.insert();
event.state = "stop_processing";
}
})(current, event, email, logger, classifier);

 

Now they want to populate the CI Name as well from the email body from Source Field into the Configuration Item field on the Incident form.

find_real_file.png

Can anyone help me out in modifying the script to make this work to populate the required CI Name from Source Field from email body to Configuration Item Field on the Incident form? It is very urgent for me to achieve this requirement and confirm with the customer.

 

Thanks

19 REPLIES 19

Hello Ian,

Please find the below screenshot for your reference.

find_real_file.png

Thank you for the screenshot.

Looking at the email.body_text and checking the split functions, it would/should be outputting "ussdap10" as the display value for the cmdb_ci field.

Does such a (lowercase) cmdb_ci field value pull up the correct/expected record? Or would it be better to be entered as "USSDAP10"?

If the uppercase is preferred, just remove the ".toLowerCase()" part of the last line.

Hello Ian,

We have uploaded our CI's as below.

find_real_file.png

Please suggest here.

I have updated the code as below,

(function runAction( /*GlideRecord*/ current, /*GlideRecord*/ event, /*EmailWrapper*/ email, /*ScopedEmailLogger*/ logger, /*EmailClassifier*/ classifier) {
gs.include('validators'); {

// var ci_name = email.body.source;
// gs.logs("Sukku Server1= " + ci_name);
// var ci_name1 = ci_name.split(":").toString();
// gs.logs("Sukku Server2= " + ci_name1);
// var name = ci_name1.split(".").toString();
// gs.logs("Sukku Server3= " + name);
// var final_ci = ci_name1;
// gs.logs("Server= " + final_ci);

var fromaddress = email.origemail;
var severity = email.body.severity;
var pri = email.body.priority;
//var ci = email.body.path;
// var ci_name1 = ci.split(".").toString();
// gs.logs("Server name = " + ci_name1);

//gs.logs("Severity= " +severity+ "\n Priority= "+pri);
// current.comments="Severity: "+severity+"\n Priority:" +pri;
current.comments = "received from: " + email.origemail + "\n\n" + email.body_text;
current.description = email.body_text;
current.short_description = email.subject + " - " + ci;
current.incident_state = 1; //Incident state = New
current.state = 1;
current.contact_type = "Alert";
current.assignment_group = 'a7d3b8241b7ab49040d9eb97624bcb01';
current.category = "server";
current.subcategory = "SCOM";
current.incident_state = 1;
current.caller_id = 'e21259021b5d85507f0132e2cd4bcbd4';
current.opened_by = 'e21259021b5d85507f0132e2cd4bcbd4';

var getSource = email.body_text;
var sourceName = [];
sourceName = getSource.toString().split("Source:");
var spl = sourceName[1].split(".");
current.cmdb_ci.setDisplayValue(spl[0]);

if (severity == 2 && pri == 2) { // P3 - Medium
current.urgency = 2;
current.impact = 2;
} else { //P4 - Low
current.urgency = 3;
current.impact = 3;
}
//current.cmdb_ci = email.body.Source;
current.insert();
event.state = "stop_processing";
}
})(current, event, email, logger, classifier);

 

Thanks

Your script looks okay to me, and everything should be working.

Now, there is one item that I have never used before and that is the event.state = "stop_processing"; one. I use the checkbox on the Inbound Action to set this.

One other thing, and hopefully it's just how it's being displayed on the page here. Can you confirm that the line var sourceName = []; is actually using a [ and a ] without a space between them? They look squished together and I can't tell.

Hello Ian,

I have updated the last line of script to UpperCase as below.

find_real_file.png

Can you please check and let me know if any modifications required here.

 

THanks