Inbound Email Action - Pass CI from 'Sender' of email

GMoon
Tera Guru

Hi all,

 

Looking for support on the correct syntax for an Inbound Email Action. We have an action in situ working, however, we now need to pass the CI (which is captured in the From field of the incoming email) into the Configuration Item field on the Incident form.

Could someone assist with adding the correct syntax to our existing script please? I believe it would be something along the lines of the below, however, I can't work out how to only pass the CI value, as opposed to all the information in the Sender field of the incoming email.

 

Thanks!

 

 

 

1 ACCEPTED SOLUTION

@GMoon 

is it prefix or suffix?

if 1st letter at the start of string is to be removed then use this line

var exampleCI = inputString.split('.')[0].substring(1).toLowerCase();

if last letter at the end of string is to be removed then use this line

var exampleCI = inputString.split('.')[0].slice(0, -1).toLowerCase();

I believe I have answered your question.

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

12 REPLIES 12

@GMoon 

is it prefix or suffix?

if 1st letter at the start of string is to be removed then use this line

var exampleCI = inputString.split('.')[0].substring(1).toLowerCase();

if last letter at the end of string is to be removed then use this line

var exampleCI = inputString.split('.')[0].slice(0, -1).toLowerCase();

I believe I have answered your question.

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Hi Ankur,

Thanks for your input, below is the code for others to reference and which has led to a solution for us.

var subject = email.subject;
var splitSubject = subject.split(':');
var body = email.body_text;
var user = email.from;
var splitCI = user.split('.');
var splitCI1 = splitCI[0];
var vCI = splitCI1.substring(0, splitCI1.length - 1);
 
//find the sys_id of the CI
var grCI = new GlideRecord('cmdb_ci');
grCI.addEncodedQuery('name=' + vCI);
grCI.query();
if (grCI.next()) {
    CI = grCI.getValue('sys_id');
gs.log('iLO CI is' + CI);
}
        incGr.update();
    }
 
//create new alert
current.short_description = "Remote site hardware problem";
current.description = email.body_text;
current.type = '8';
current.cmdb_ci = CI;
current.assignment_group =  gs.getProperty('xxxx');
current.priority = '3';
current.contact_type = 'alert';
current.urgency = '3';
current.impact = '3';
current.category = 'Application';
current.insert();
event.state="stop_processing";

 



 

@GMoon 

It seems you marked your own response as correct.

Would you mind marking my response as correct since it helped.

It will help to recognize the efforts I took to help you in the thread.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader