Inbound action to pull text from subject and enter into field

hinakshi
Giga Contributor

Hi All,

I have some inbound actions set up for till alerts that we receive. An example of the subject is 'POS:SELF-T1183-9999-843-HTTP Connector'

I need to extract the 'T1183' from the subject and enter it into the the Configuration Item field on the Incident table. The 'POS:SELF-' should always remain the same. The rest of the subject will change depending on the till and alert.

find_real_file.png

find_real_file.png

Can anyone help with the scripting please?

Kind regards,

Hinakshi

6 REPLIES 6

krushikesh
Kilo Guru

Hi, 

Use the email.subject Contains the subject of the email as a plain text string.

 

 

Reference https://docs.servicenow.com/bundle/newyork-servicenow-platform/page/administer/notification/referenc...

rajesh9885
Mega Guru

Please try this in your code

var str = "POS:SELF-T1183-9999-843-HTTP Connector!";
var res = str.substring(9, 14);

Manas Kandekar
Kilo Guru

Hi

You can use

var data = email.subject;

 
var text = data.split('-')[1];
 
 
 
If my answer helped you in any way, please then mark it correct and helpful.

Kind regards,
Manas
 

AbhishekGardade
Giga Sage

Hello Hinkanshi,

You can fetch it like below:

var subject = 'POS:SELF-T1183-9999-843-HTTP Connector';

var outputValue = subject.split('-'); // it will split a string after every -. Array index starts with ZERO

gs.print("1 st element: "+outputValue[0]); // here 0 Zero is index 

gs.print("outputValue: "+outputValue[1]);// here 1 ONE is index 


Please mark as Correct Answer and Helpful, if applicable.
Thanks!
Abhishek Gardade
Hexaware Technologies

Thank you,
Abhishek Gardade