- 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:21 PM
Hi,
why not use contains query
var gr = new GlideRecord('incident');
gr.addQuery('short_description', 'LIKE' ,'INC0528025');
gr.query();
while(gr.next())
{
gs.log("Found it");
}
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:24 PM
Hi Ankur thank you for replying,
The incident# in the short description is not fixed, it can be any number and not that incident's number. I wont know what that number is.
I need to fetch that number and use it to query another sys_email table for its emails.
Thats why I cant use it that way.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-21-2020 11:36 PM
Hi,
you can use regular expression to get the incident number from short_description
like this
var gr = new GlideRecord('incident');
gr.addQuery('number','INC0528025');
gr.query();
if(gr.next())
{
var shortDesc = gr.short_description.toString();
var regex = new SNC.Regex('/INC\\d{7}/im');
var incNumber = regex.match(shortDesc);
gs.log(incNumber);
gs.log("Found it");
}
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: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-22-2020 12:47 AM
Thank you Ankur,
I have never used Regex, it is an interesting find and it gave me the incident number. Thanks so much!