Analyze UI action to show related Problem tickets

sattar3
Tera Contributor

Hello All,

 

I’ve added an 'Analyze' button to the Problem record form.

When clicked on that button, I want it to display all other Problem records whose short description or description contains keywords similar to those in the current Problem record.

 

Example: if the word 'Interface' appears, it should return all related Problem records with 'Interface' in their short description or description. How can I implement this functionality?"

 

@Ankur Bawiskar 

 

Thanks,

Sattar

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

@sattar3 

make the UI action as client side, something like this and it will show the list of problem within UI page

GlideDialogWindow: Popup Record List 

UI Action: on problem table

Client - True

Onclick - showProblem()

Script:

function showProblem() {
    var w = new GlideDialogWindow('show_list');
    w.setTitle('Associated Problems');
    w.setPreference('table', 'problem_list');
    w.setPreference('sysparm_view', 'default');
    //Set the query for the list
    var desc = g_form.getValue('description');
    var shortDesc = g_form.getValue('short_description');
    var query = 'short_descriptionLIKE' + shortDesc + '^ORdescriptionLIKE' + desc;
    w.setPreference('sysparm_query', query);
    //Open the popup
    w.render();
}

AnkurBawiskar_0-1747028400098.png

 

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

6 REPLIES 6

mohdarbaz
Kilo Guru

Hi @sattar3 ,

-Create a Script Include that will handle the logic for fetching related Problem records based on keywords. This Script Include will be called from the client-side when the 'Analyze' button is clicked.

 

var ProblemAnalyzer = Class.create();
ProblemAnalyzer.prototype = {
initialize: function() {},

getRelatedProblems: function(currentProblemId) {
var currentProblem = new GlideRecord('problem');
currentProblem.get(currentProblemId);

var keywords = currentProblem.short_description + ' ' + currentProblem.description;
var keywordArray = keywords.split(' ');

var relatedProblems = [];
var problemGR = new GlideRecord('problem');
problemGR.addEncodedQuery('short_descriptionLIKE' + keywordArray.join('^ORdescriptionLIKE'));
problemGR.query();

while (problemGR.next()) {
relatedProblems.push({
sys_id: problemGR.sys_id.toString(),
short_description: problemGR.short_description.toString(),
description: problemGR.description.toString()
});
}

return relatedProblems;
},

type: 'ProblemAnalyzer'
};

------------------------------------------------------

-Next, create a client script that will be triggered when the 'Analyze' button is clicked. This script will call the Script Include and display the related Problem records.

 

var currentProblemId = g_form.getUniqueValue();
   
    var ga = new GlideAjax('ProblemAnalyzer');
    ga.addParam('sys_id', currentProblemId);
    ga.getXMLAnswer(function(response) {
        var relatedProblems = JSON.parse(response);
       
        var relatedProblemsHTML = '<ul>';
        relatedProblems.forEach(function(problem) {
            relatedProblemsHTML += '<li>' + problem.short_description + ': ' + problem.description + '</li>';
        });
        relatedProblemsHTML += '</ul>';
       
        var dialog = new GlideDialogWindow('related_problems_dialog');
        dialog.setTitle('Related Problems');
        dialog.setBody(relatedProblemsHTML, false, false);
        dialog.render();
    });
-----------------------------------------------------------------------

-Add the 'Analyze' button to the Problem record form and link it to the Client Script.

 

<button onclick="onAnalyzeButtonClick()">Analyze</button>

 

If my response helped, please mark it correct/helpful and close the thread so that it benefits future readers.

 

Regards,

Mohd Arbaz.

 

Ankur Bawiskar
Tera Patron
Tera Patron

@sattar3 

it's an easy requirement.

what script did you write so far and where are you stuck?

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Ankur Bawiskar
Tera Patron
Tera Patron

@sattar3 

make the UI action as client side, something like this and it will show the list of problem within UI page

GlideDialogWindow: Popup Record List 

UI Action: on problem table

Client - True

Onclick - showProblem()

Script:

function showProblem() {
    var w = new GlideDialogWindow('show_list');
    w.setTitle('Associated Problems');
    w.setPreference('table', 'problem_list');
    w.setPreference('sysparm_view', 'default');
    //Set the query for the list
    var desc = g_form.getValue('description');
    var shortDesc = g_form.getValue('short_description');
    var query = 'short_descriptionLIKE' + shortDesc + '^ORdescriptionLIKE' + desc;
    w.setPreference('sysparm_query', query);
    //Open the popup
    w.render();
}

AnkurBawiskar_0-1747028400098.png

 

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Shree_G
Mega Sage

Hello @sattar3 ,

 

Are you looking for the similar functionality of "Related Search".

 

Change the filter of the "Related Search" to "Problem" instead of default "Knowledge" and it will give all the related Problem records which has Description with matching keywords.

 

Shree_G_0-1747028828540.png

 

If you need to add more fileds in search results,

  1. Navigate to All > Contextual Search > Table Configuration.
  2. Open the record for the table whose form you want to show the related search box on and configure the search fields.

 

Shree_G_1-1747029040088.png

 

 


If this solution helped resolve your issue, please consider marking it as helpful or correct.
This will assist others in finding the solution faster and close the thread.