- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-01-2025 06:28 AM
Hi All,
Below is the subject line from email. We would need to populate as below in a table.
"CS-1328006 ITP Escalation: Medium Identity Threat Detection".
"CS-1328006" in Ticket Number field which is a string type. "1328006" This digit is not the same every time.
And it should check the priority from the subject.
Here, it contains "Medium" So the Priority in the ticket should set to 3 - Medium.
Please assist.
Thanks & Regards.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-01-2025 07:43 AM
the script I shared should extract the values
Refer below script which gives the correct output. once you get the values you can then set in target record
var subject = "CS-1328006 ITP Escalation: Medium Identity Threat Detection";
// Extract the ticket number (CS-1328006)
var ticketNumberMatch = subject.match(/CS-\d+/);
var ticketNumber = ticketNumberMatch ? ticketNumberMatch[0] : '';
// Extract the priority (Medium)
var priorityMatch = subject.match(/(Low|Medium|High)/i);
var priority = priorityMatch ? priorityMatch[0].toLowerCase() : '';
gs.info('Ticket number->' + ticketNumber);
gs.info('Priority->' + priority);
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
04-01-2025 06:32 AM - edited 04-01-2025 06:34 AM
are you using this in inbound action of incident?
if yes then update the script as this to set priority as Medium and the string field
var subject = email.subject;
// Extract the ticket number (CS-1328006)
var ticketNumberMatch = subject.match(/CS-\d+/);
var ticketNumber = ticketNumberMatch ? ticketNumberMatch[0] : '';
// Extract the priority (Medium)
var priorityMatch = subject.match(/(Low|Medium|High)/i);
var priority = priorityMatch ? priorityMatch[0].toLowerCase() : '';
// Map priority to numeric value
var priorityValue;
switch (priority) {
case 'low':
priorityValue = 4;
break;
case 'medium':
priorityValue = 3;
break;
case 'high':
priorityValue = 1;
break;
default:
priorityValue = 3; // Default to Medium if not found
}
// Create or update the record in the target table
var gr = new GlideRecord('incident'); // Change 'incident' to your target table
gr.initialize();
gr.short_description = subject;
gr.stringField = ticketNumber;
gr.priority = priorityValue;
gr.insert();
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
04-01-2025 07:43 AM
the script I shared should extract the values
Refer below script which gives the correct output. once you get the values you can then set in target record
var subject = "CS-1328006 ITP Escalation: Medium Identity Threat Detection";
// Extract the ticket number (CS-1328006)
var ticketNumberMatch = subject.match(/CS-\d+/);
var ticketNumber = ticketNumberMatch ? ticketNumberMatch[0] : '';
// Extract the priority (Medium)
var priorityMatch = subject.match(/(Low|Medium|High)/i);
var priority = priorityMatch ? priorityMatch[0].toLowerCase() : '';
gs.info('Ticket number->' + ticketNumber);
gs.info('Priority->' + priority);
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
04-01-2025 07:03 AM
Hello @Joshuu
I had replied in your previous post as well for sharing the subject line. Could you please accept my solution there and close the thread ?
Well, below 👇 shared it - that's simple approach as it's not depending on length or anything.
(function executeRule(current, previous /*null when async*/) {
var inputString = current.short_description.toString(); // Assuming short description field
var csNumberMatch = inputString.match(/CS-\d+/); // Extract CS number
var priority = "High"; // Default to High
if (inputString.toLowerCase().includes("medium")) {
priority = "Medium";
} else if (inputString.toLowerCase().includes("low")) {
priority = "Low";
}
if (csNumberMatch) {
current.u_cs_number = csNumberMatch[0]; // Assuming a custom field u_cs_number
}
current.priority = priority; // Set the priority
})(current, previous);
Kindly mark my answer as helpful and accept solution if it helped you in anyway. This will help me be recognized for the efforts and also move this questions from unsolved to solved bucket.
Regards,
Shivalika
My LinkedIn - https://www.linkedin.com/in/shivalika-gupta-540346194
My youtube - https://youtube.com/playlist?list=PLsHuNzTdkE5Cn4PyS7HdV0Vg8JsfdgQlA&si=0WynLcOwNeEISQCY
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-02-2025 09:14 AM
Hello @Joshuu
Did you try my solution as well ? I tested it out similar to various subject lines like yours and it's also working.
If you found that helpful or valuable. Kindly consider accepting my solution as well.
Regards,
Shivalika
My LinkedIn - https://www.linkedin.com/in/shivalika-gupta-540346194
My youtube - https://youtube.com/playlist?list=PLsHuNzTdkE5Cn4PyS7HdV0Vg8JsfdgQlA&si=0WynLcOwNeEISQCY