- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-21-2020 10:45 PM
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);
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-21-2020 11:37 PM
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:
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-21-2020 11:06 PM
Hi,
You can use the contains query on short_description.
Can you explain where is this script required
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-21-2020 11:07 PM
Hi Ankur,
I need the script in a business rule.
I need to fetch the incident number from short description and run a query on sys_email table based on that Incident number fetched. I have never fetched or stored a string in servicenow so i cant find it..

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-21-2020 11:09 PM
Hi,
you can try like this.
//short_desc is a variable in which short description present
if(short_desc.indexOf("INC")>-1) {
short_desc = short_desc.split(" ");
var number = short_desc[4]; //as you mentioned number will be in 5th position
gs.print(number);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-21-2020 11:19 PM
Thank you for the reply asifnoor.
I used the code in the background script, but it gave the output as "undefined".
I used the following:
var gr = new GlideRecord('incident');
gr.addQuery('number','INC0528025');
gr.query();
while(gr.next())
{
gr.short_description = gr.short_description.split("/");
var n = gr.short_description[4]; //as you mentioned number will be in 5th position
gs.log(n);
gs.log("Found it");
}
The output was:
*** Script: undefined
*** Script: Found it
The short description contains:
INC# INC0528025 / ATT_NI_RMM_VC_ABCDE / 1 - Critical / New / GENERIC DEVICE / test