Check for other incidents already attached to a change when adding to caused_by change

Susan Davidson
Giga Guru

We are ending up with multiple incidents attached to changes via the caused_by field leading to more than one "master" ticket in the service desk.

 

I would like to put something in place that when the agents go to the caused_by field on the incident and search for a change number and select it then it would tell them if there are already other incidents that have had that same change number entered into the caused_by field and what those incident numbers are.

I cannot wrap my head around where to start with that one. Any ideas?

1 ACCEPTED SOLUTION

POOJA SINGH18
Mega Guru

Hi Susan,

 

One of the best practice of achieve your solution is to make a Ajax call. Writing GlideRecord in client script is not a good practice in ServiceNow. 

So write a function in a Script Include, follow below:

POOJASINGH18_0-1689573813264.png

 

and then make a Ajax call using "OnChange" Client script.


POOJASINGH18_1-1689573898505.png


The end result will be something like below:

POOJASINGH18_2-1689573956666.png

 

Hope it helps and please mark helpful if it solves the issue.

Thanks,

Pooja Singh

 

View solution in original post

6 REPLIES 6

Bert_c1
Kilo Patron

hi Susan,

 

Seems a Client Script can do that, I tried a quick attempt, popups appear when a CHG is entered in the 'Caused by Change' field on incident. see screenshot:

 

Screenshot 2023-07-16 220216.png

Other means may exist depending on the desired user experience. The script logic above can be modified to show a single 'alert' with all incidents if desired.

This looks great - i changed it to a message as that's what higher ups want but i really like it.
Would love to know how to get all the related incidents showing if you already know how to do that?!
Thank you for taking the time

Well.. I got it working in the UI with the list of incident tickets already linked to a change (if there are any)

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
   if (isLoading || newValue === '') {
      return;
   }

var IncChg = [];
var inc = new GlideRecord('incident');
//inc.addActiveQuery();
inc.addQuery('caused_by', newValue);
inc.query();
while (inc.next()) {
    IncChg.push(inc.number);
}
	if (IncChg.length >= 1)
		{
alert("The following ticket(s) have already been opened as being caused by this change: " + IncChg); }
	
}

 

It doesn't however show up on the incident form on workspaces... *sigh* which is where it is needed most.
Can it be made to show on workspace

POOJA SINGH18
Mega Guru

Hi Susan,

 

One of the best practice of achieve your solution is to make a Ajax call. Writing GlideRecord in client script is not a good practice in ServiceNow. 

So write a function in a Script Include, follow below:

POOJASINGH18_0-1689573813264.png

 

and then make a Ajax call using "OnChange" Client script.


POOJASINGH18_1-1689573898505.png


The end result will be something like below:

POOJASINGH18_2-1689573956666.png

 

Hope it helps and please mark helpful if it solves the issue.

Thanks,

Pooja Singh