- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-07-2025 05:12 AM
Hello Everyone
I have a requirement to pick only incident number from the updated work note of the sctask using email script.
Please suggest me on this. for your reference attached screenshot
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-07-2025 05:40 AM
you didn't pass any string so how it will get the INC number from it.
since you want it from latest work notes use this
var str = current.work_notes.getJournalEntry(1);
var regex = new SNC.Regex('/INC\\d{7}/im');
var match = regex.match(str);
template.print('Incident: ' + match);
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-07-2025 05:43 AM - edited 07-07-2025 05:44 AM
@Vinod S Patil See if this helps you
This is working script which will help you to extract the incident number from the Work Notes. Kindly note that if you have customized the Incident Number formatting then regex needs to be altered accordingly. Below script will perfectly work for you in PDI as it is OOB.
var incGR = new GlideRecord('incident');
if (incGR.get('INC0010018')) {
var incidentSysId = incGR.getUniqueValue();
var journalGR = new GlideRecord('sys_journal_field');
journalGR.addQuery('element_id', incidentSysId);
journalGR.addQuery('element', 'work_notes');
journalGR.query();
var regex = /INC\d{7}/g;
var foundIncidents = [];
while (journalGR.next()) {
var note = journalGR.getValue('value');
var matches = note.match(regex);
if (matches) {
for (var i = 0; i < matches.length; i++) {
if (foundIncidents.indexOf(matches[i]) === -1) {
foundIncidents.push(matches[i]);
}
}
}
}
if (foundIncidents.length > 0) {
gs.print('Incident Numbers found in work notes of INC0010018:');
for (var j = 0; j < foundIncidents.length; j++) {
gs.print(foundIncidents[j]);
}
} else {
gs.print('No Incident Numbers found in work notes.');
}
} else {
gs.print('Incident INC0010018 not found.');
}
Outcome of the script would be something like this:
✔️ If this solves your issue, please mark it as Correct.
✔️ If you found it helpful, please mark it as Helpful.
—
Shubham Jain
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-07-2025 05:16 AM
in email script you need to use RegEx to extract incident number
something like this you can use and enhance for your requirement
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);
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-07-2025 05:34 AM
@Ankur Bawiskar
Below code not working the email script, can you suggest
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-07-2025 05:40 AM
you didn't pass any string so how it will get the INC number from it.
since you want it from latest work notes use this
var str = current.work_notes.getJournalEntry(1);
var regex = new SNC.Regex('/INC\\d{7}/im');
var match = regex.match(str);
template.print('Incident: ' + match);
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-07-2025 05:43 AM - edited 07-07-2025 05:44 AM
@Vinod S Patil See if this helps you
This is working script which will help you to extract the incident number from the Work Notes. Kindly note that if you have customized the Incident Number formatting then regex needs to be altered accordingly. Below script will perfectly work for you in PDI as it is OOB.
var incGR = new GlideRecord('incident');
if (incGR.get('INC0010018')) {
var incidentSysId = incGR.getUniqueValue();
var journalGR = new GlideRecord('sys_journal_field');
journalGR.addQuery('element_id', incidentSysId);
journalGR.addQuery('element', 'work_notes');
journalGR.query();
var regex = /INC\d{7}/g;
var foundIncidents = [];
while (journalGR.next()) {
var note = journalGR.getValue('value');
var matches = note.match(regex);
if (matches) {
for (var i = 0; i < matches.length; i++) {
if (foundIncidents.indexOf(matches[i]) === -1) {
foundIncidents.push(matches[i]);
}
}
}
}
if (foundIncidents.length > 0) {
gs.print('Incident Numbers found in work notes of INC0010018:');
for (var j = 0; j < foundIncidents.length; j++) {
gs.print(foundIncidents[j]);
}
} else {
gs.print('No Incident Numbers found in work notes.');
}
} else {
gs.print('Incident INC0010018 not found.');
}
Outcome of the script would be something like this:
✔️ If this solves your issue, please mark it as Correct.
✔️ If you found it helpful, please mark it as Helpful.
—
Shubham Jain