How can i script a BR to search for a substring in an incident's short description?

Ashirav
Tera Expert

Hello All,

I need that if a specific incident's short description is containing incident number, then that incident number should be stored in a variable.

Is there a way in scripting how I can extract that text from the short description? The words are at the 5th position index in the short description.

 

I tried the following in background script but its not working:-

var gr = new GlideRecord('incident');
gr.addQuery('number','INC0533650');
gr.query();
while(gr.next())
{
var res = sgr.short_description.substring(5, 10);
gs.log("Found it");
gs.log(res);
}

1 ACCEPTED SOLUTION

@Ashirav 

Script I tried with your short description and got the incident number

var str = 'INC# INC0528025 / ATT_NI_RMM_VC_ABCDE  / 1 - Critical / New / GENERIC DEVICE / test';

var regex = new SNC.Regex('/INC\\d{7}/im');

var match = regex.match(str);

gs.info('Incident number->' + match);

Output:

find_real_file.png

Regards
Ankur

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

View solution in original post

15 REPLIES 15

JanneHjorth
Tera Contributor

Hi David.

 

I'm having this issue regarding finding values in task short description.

So if my short description field holds this information:

CTD sendt via API, lev. nr. 3310, Bilags nr. 118645, Type: EDI Faktura

 

I need to get the information after word Type: into the task field "Category".

How would you do that??

 

I have tryed with this script:

var gam_type = /Type: (.*?)\./g; //new RegExp("Type: (.*?)\.", "g");
var type_match = gam_type.exec(email.subject);
if(type_match && type_match[1]) {
current.category.setDisplayValue(type_match[1].toString());
}

 

But It dosn't work.

And the Type information can be placed at different positions, as we get the information from customers via mail.

Kind regards,

Janne.