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

Ian Mildon
Tera Guru

You can use the Split function like I'm doing in this example:

(function runAction(/*GlideRecord*/ current, /*GlideRecord*/ event, /*EmailWrapper*/ email, /*ScopedEmailLogger*/ logger, /*EmailClassifier*/ classifier) {
	// Implement email action here
	current.caller_id = "b47e331c1b420d1068880d85624bcb9e"; //* user profile with email = Application, NetApp (NetApp) - ocumiq@unch.unc.edu
    current.u_best_contact_method = "email";
    current.u_best_contact_name = "DoNotReply";
    current.u_room_suite_information = 'n/a'; //* needed to add for P2 
    current.u_loc_conf = true; //* needed to add for P2
    current.business_service = "8068e708dbc5be00deda327e9d961920"; //* Epic@UNC
	current.contact_type = "Email";
    current.category = "Hardware";
    current.subcategory = "Server";
	current.impact = 2;
    current.urgency = 1;
	// current.cmdb_ci = ; //* get from email below
    current.assignment_group = "8634b5badb05b240ec5c3c00ad961918"; //* ISD Team Storage
    current.u_department = "fd6ccf3cdb05be00ec5c3c00ad96196f"; //* File Storage
    current.short_description = email.subject + " Volume (" +volumeInfo+ ")"; //* get from email and split value
	current.description = email.body_text;
	
    var getCluster = email.body_text;
    var clusterName = [];
    clusterName = getCluster.toString().split("Cluster Name  - "); //! there are two spaces between Name and -
    var spl = clusterName[1].split("\n"); //* split at carriage return
    current.cmdb_ci.setDisplayValue(spl[0].toLowerCase()); //* set the extracted name value

    var getVolume = email.body_text;
    var volumeName = [];
    volumeName = getVolume.toString().split("volumes/"); //* email body Source Details line
    var splVol = volumeName[1].split("\n"); //* split at carriage return
    var volumeInfo = splVol[0].toString(); //* extracted volume data (number string)

	current.insert();
})(current, event, email, logger, classifier);

Pay attention to the "clusterName" section as that is doing what you are wanting.

In your case the use ".split("Source: ") for the "spl"

Hello Ian,

(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';

var getCluster = email.body_text;
var clusterName = [];
clusterName = getCluster.toString().split("Cluster Name - "); //! there are two spaces between Name and -
var spl = clusterName[1].split("\n"); //* split at carriage return
current.cmdb_ci.setDisplayValue(spl[0].toLowerCase()); //* set the extracted name value

var getVolume = email.body_text;
var volumeName = [];
volumeName = getVolume.toString().split("Source/"); //* email body Source Details line
var splVol = volumeName[1].split("\n"); //* split at carriage return
var volumeInfo = splVol[0].toString(); //* extracted volume data (number string)

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);

 

Can you please verify if my script looks good as per your suggestions? Or do I need to add the Source field somewhere else as well?

 

Thanks

Looking at your email sample, the "Source line" looks like:

Source: <source id>.<network address>

And you are just wanting the <source id> bit; so you would want to use something like this.

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

This will get the value after the "Source: " text, then the split will stop at the period after the value you are wanting, then it will insert the value to the cmdb_ci field.

Hello Ian,

I have found some differences in the Source which is coming as email subject as below.

find_real_file.png

And in the email body as below.

find_real_file.png

The difference is in the Subject there is some space after "Source: " but in the email body there is no space after "Source:"

 And in this case the CI Name is coming as USSDF03.xyz.com but in our CMDB Database in SNOW we have the CI Name uploaded as only USSDF03 Name. So will the code work for me?

 

Thanks