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

Chavan AP
Kilo Sage

hey hi ,

 

Please use below code , i have tested this and works fine

var str="POS:SELF-T1183-9999-843-HTTP Connector";
var keyword="SELF-";
var len = keyword.length;
var key = str.indexOf(keyword);

if(key > 0 || key == 0){
var num = str.substring(key+len,key+len+5);

	//below code is to query cmdb table and get the sys_id of the ci then update incident field
	var ch=new GlideRecord('cmdb_ci');
	ch.query('name',num);
	ch.query();
	while(ch.next())
		{
   gs.log('change sys id is:'+ch.sys_id);// this will give you sys_id of CI
	current.setValue('cmdb_ci','ch.sys_id');
			
	}
}

 

output SS:

 

Glad I could help! If this solved your issue, please mark it as ✅ Helpful and ✅ Accept as Solution so others can benefit too.*****Chavan A.P. | Technical Architect | Certified Professional*****

I tried this, but it is not putting the T number (T1183) into the config item (cmdb_ci) field.