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

Ankur Bawiskar
Tera Patron
Tera Patron

@GMoon 

the from field in inbound is the recipient i.e. some email address

how will you set that in CI field?

CI field on incident refers cmdb_ci table

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,
These particular emails are like the below, they don't come from a 'typical' sender but a relay which has the CI prefixed at the start.

From: EXAMPLECI.xxxx.local@smtprelay.xxx.local  

These CI's are all in our cmdb_ci table.

@GMoon 

then is "EXAMPLECI" a name of CI in cmdb_ci table?

If yes then this try this

// see where this email comes either from email.fromAddress	or email.from or email.origemail

var inputString = email.fromAddress.toString();

// Extract the EXAMPLECI part
var exampleCI = inputString.split('.')[0].toLowerCase();

// Query the cmdb_ci table to find the matching record
var ciGr = new GlideRecord('cmdb_ci');
ciGr.addQuery('name', exampleCI);
ciGr.query();
if (ciGr.next()) {
    var sysId = ciGr.sys_id;
    current.cmdb_ci = sysId;
}

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

@GMoon 

Thank you for marking my response as helpful.

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,

Our testing was unsuccessful but I have noticed the CI format contained within the incoming email is prefixing an additional letter on the end, therefore I feel that may be our issue.
This is a long shot but is there any way we can change the script to omit the additional letter?

 

Thanks