diff --git a/Server-Side Components/Background Scripts/Find Similar Tickets/README.md b/Server-Side Components/Background Scripts/Find Similar Tickets/README.md new file mode 100644 index 0000000000..04f7884978 --- /dev/null +++ b/Server-Side Components/Background Scripts/Find Similar Tickets/README.md @@ -0,0 +1,32 @@ +This script identifies tickets similar to a given ticket in ServiceNow based on text similarity of short_description and description fields, optionally boosting the score for matching categories or assignment groups. It is intended for background script execution for testing, analysis, or automation purposes. + +**Features:** +1) Compares a source ticket against other tickets in the same table (incident by default). +2) Computes Jaccard similarity between tokenized text fields. +3) Applies bonus points for matching category and assignment_group. +4) Returns a sorted list of similar tickets with score, number, caller_id and short_description. +5) Supports top N results and a minimum score filter. + + +**Usage:** +1) Paste the script in scripts-background. +2) Make changes to the sys_id of your ticket in line no. 3 +3) click run to get an output as below + +**Output:** + * *** Script: === Similar Tickets to: INC0010005 === + * *** Script: INC0010006 | Score: 1.08 | undefined | Sai Test INC0008112 + * *** Script: INC0010004 | Score: 0.58 | undefined | Sai Test INC0009005 + * *** Script: INC0009009 | Score: 0.161 | undefined | Unable to access the shared folder.test + * *** Script: INC0008001 | Score: 0.08 | undefined | ATF:TEST2 + * *** Script: INC0000020 | Score: 0.08 | undefined | I need a replacement iPhone, please + * *** Script: INC0000031 | Score: 0.08 | undefined | Need help with Remedy. Can we configure UI? + * *** Script: INC0000040 | Score: 0.08 | undefined | JavaScript error on hiring page of corporate website + * *** Script: INC0010002 | Score: 0.08 | undefined | + * *** Script: INC0000057 | Score: 0.08 | undefined | Performance problems with wifi + * *** Script: INC0010003 | Score: 0.08 | undefined | + +**Explanation of the output:** +1) First Line contains the ticket which you have provided as a sys_id. +2) Next lines contains the ticket which contain ticket no. | score | caller_id | short_description. +3) If you keenly observe there are few tickets that do not have similar short description / description with scores as 0.08 but still in output the reason for this is their category and assignment group still matches with the compared ticket. diff --git a/Server-Side Components/Background Scripts/Find Similar Tickets/findSimilarTickets.js b/Server-Side Components/Background Scripts/Find Similar Tickets/findSimilarTickets.js new file mode 100644 index 0000000000..38dda6497d --- /dev/null +++ b/Server-Side Components/Background Scripts/Find Similar Tickets/findSimilarTickets.js @@ -0,0 +1,82 @@ +(function() { + var table = 'incident'; //can be used for other tickets as well + var sourceSysId = 'f4755b82c3203210348bbd33e40131cb'; // sys_id of the ticket which is used to find similar tickets + var limit = 10; // top N results + var minScore = 0.05; + + function tokensFromText(text) { + if (!text) return []; + text = text.toLowerCase().replace(/[^a-z0-9\s]/g, ' '); + var raw = text.split(/\s+/); + var stop = { + 'the':1,'and':1,'for':1,'with':1,'that':1,'this':1,'from':1,'have':1,'has':1,'was':1,'were':1, + 'a':1,'an':1,'is':1,'in':1,'on':1,'of':1,'to':1,'it':1,'as':1,'by':1,'be':1,'are':1 + }; + var map = {}; + for (var i=0;i