How to parse data from Email subject and put in Incident field

Nisha30
Kilo Sage

Hello Experts,

 

Can you please assist how do I parse the value from the below subject line and put in Incident fields

 

Windows Alert::DeviceDown::GH56CCVNH.aeb.ca::10.12.212.14::critical

 

I want GH56CCVNH in Configuration Item field

and critical as P1 in Priority field.

 

Can anyone assist how to extract them

Thanks

 

1 ACCEPTED SOLUTION

Gangadhar Ravi
Giga Sage
Giga Sage

@Nisha30 Please try something like below.

var subject = email.subject;
var subjectParts = subject.split("::");

var ci = subjectParts[2].split(".")[0];
var priority = subjectParts[4].toLowerCase() == 'critical' ? 1 : 3;

current.cmdb_ci = getCI(ci);
current.priority = priority;

function getCI(ciName) {
    var ciRecord = new GlideRecord('cmdb_ci');
    ciRecord.addQuery('name', ciName);
    ciRecord.query();
    if (ciRecord.next()) {
        return ciRecord.sys_id;
    }
    return null;
}

Please mark my answer correct and helpful if this works for you. 

View solution in original post

4 REPLIES 4

Gangadhar Ravi
Giga Sage
Giga Sage

@Nisha30 Please try something like below.

var subject = email.subject;
var subjectParts = subject.split("::");

var ci = subjectParts[2].split(".")[0];
var priority = subjectParts[4].toLowerCase() == 'critical' ? 1 : 3;

current.cmdb_ci = getCI(ci);
current.priority = priority;

function getCI(ciName) {
    var ciRecord = new GlideRecord('cmdb_ci');
    ciRecord.addQuery('name', ciName);
    ciRecord.query();
    if (ciRecord.next()) {
        return ciRecord.sys_id;
    }
    return null;
}

Please mark my answer correct and helpful if this works for you. 

Thanks @Gangadhar Ravi  it worked perfectly. Thanks for instant response.

Just one thing about priority what is meant by 1:3 ? here It is P4 coming as per this code 

Gangadhar Ravi
Giga Sage
Giga Sage

The expression 1 : 3 is used in a quick "if-else" check:

  • If the condition is true (in this case, if the word is "critical"), it sets the value to 1.
  • If the condition is false (anything else), it sets the value to 3.

@Gangadhar Ravi so the priority is always setting to p4 here as per this code .

so here actually

if critical it should be P1

If medium- P3

If low- P4

If High-P2

 

Can you assist on this 

Thanks