Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Email content retrieval from Flow Designer

DB1
Tera Contributor

Hi All,

I need help on retrieving/ extracting the content of the inbound email body text content and set it as the CI of the Incident create.

For example:

If the email.body_text = "This message is a test : CINAME - AIXserver" 

I am looking for help to extract the word "AIXserver" dynamically (as it could change for other mails) considering the fact that "CINAME -" suffix will not change so basically any word after CIName using Flow Designer.

Request help on how this can be acheived.

 

Thanks,

DB

 

4 REPLIES 4

Vasantharajan N
Tera Sage
Tera Sage

If the pattern is known, Please use regular Expression to extract the word that you wanted.


Thanks & Regards,
Vasanth

DB1
Tera Contributor

Hi,

I was able to manage the script to extract the characters from email. However it returns the string as Array

Example ["IOS","Android"]

Now the  requirement is to use the above array in a query to return sys id of the cmdb record.

I am stuck with how to achieve the same.

Below is the code I am trying, however it returns only one sys id of the first array twice

for example if arr returns - ["IOS","Android"]

outputs.ci = arr; //return parsed name/val pairs
//var ci = arr.toString();
outputs.not_an_Error = "true";
var json_arr = JSON.stringify(arr);
//var json_arr = arr;
var myString1Split = json_arr.split(',');
gs.log('Body json ' +myString1Split + json_arr);
var str = '';
for(i=0;i<myString1Split.length;i++){
var mylst = new GlideRecord('cmdb_ci');
//mylst.addEncodedQuery('nameIN'+myString1Split[i]);
mylst.addEncodedQuery('name','IN',json_arr);
gs.log('Body name '+myString1Split[i]);
mylst.query();
if(mylst.next()){

//str = mylst.push(mylst.getValue('sys_id'));
str += mylst.sys_id+',';
gs.log('body Json str ' +str);
outputs.ci_sysid = str;
//return str;
//outputs.ci_sysid = str.sys_id;

}
}

})(inputs, outputs);

 

request to help on parsing the above 2 array to return as sys id

Uncle Rob
Kilo Patron

I do something similar in this video.

 

DB1
Tera Contributor

Hi Robert,

Yes I started with the guidance of your video and I was able to extract and return the names of CI from EMail Body, Now that returns the names in Array. Example : ["ios","android"]

Now I am looking for help to pass the above array to be queried from cmdb_ci so that I can return sys ids for the same.

 

outputs.ci = arr; //return parsed name/val pairs
//var ci = arr.toString();
outputs.not_an_Error = "true";
var json_arr = JSON.stringify(arr);
//var json_arr = arr;
var myString1Split = json_arr.split(',');
gs.log('Body json ' +myString1Split + json_arr);
var str = '';
for(i=0;i<myString1Split.length;i++){
var mylst = new GlideRecord('cmdb_ci');
//mylst.addEncodedQuery('nameIN'+myString1Split[i]);
mylst.addEncodedQuery('name','IN',json_arr);
gs.log('Body name '+myString1Split[i]);
mylst.query();
if(mylst.next()){

//str = mylst.push(mylst.getValue('sys_id'));
str += mylst.sys_id+',';
gs.log('body Json str ' +str);
outputs.ci_sysid = str;
//return str;
//outputs.ci_sysid = str.sys_id;

}