- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-16-2023 05:26 PM
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?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-16-2023 11:06 PM
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:
and then make a Ajax call using "OnChange" Client script.
The end result will be something like below:
Hope it helps and please mark helpful if it solves the issue.
Thanks,
Pooja Singh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-17-2023 08:40 AM - edited 07-17-2023 02:40 PM
Hi Susan,
Pooja makes a good point on using GlideRecord in a client script. while it can work the better approach is using GlideAjax. I was able to do that, all incidents are returned and shown in the popup. I am not aware why this approach, using GlideAjax, wouldn't work on "workspaces...". I tried using the Agent workspace and found it doesn't work there. I'm not familiar with that Feature/UI and can't comment on that aspect. I can share my code (somewhat different than above and works outside of 'Workspace') so you can cut-and-paste in your own Client Script and Script Include if desired.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-17-2023 03:06 PM
I've read KB0827632, and made a change to my Client Script, it works in Agent Workspace too now.
UI Type being set to 'All' worked. script:
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
//Type appropriate comment here, and begin script below
var ga = new GlideAjax('GetChgIncidents'); // GetChgIncidents is the script include name
ga.addParam('sysparm_name','incidentList'); // is the function in the script include that we're calling
var chg = g_form.getValue("caused_by");
ga.addParam('sysparm_chg_sysid', chg);
/* CallGetChgIncidents and use the callback function chgParse() to return the result when ready */
ga.getXMLAnswer(chgParse);
}
// callback function for returning the result from the script include
function chgParse(response) {
if (response.length > 2)
alert("Incidents with same Caused by Change: " + response);
}
Script Include:
Script:
var GetChgIncidents = Class.create();
GetChgIncidents.prototype = Object.extendsObject(AbstractAjaxProcessor, {
incidentList: function() {
var chgSysID = this.getParameter("sysparm_chg_sysid");
var result = "";
// gs.info("GetChgIncidents Checking for CHG: " + chgSysID);
// Build the payload. You can return additional data if needed.
var incr = new GlideRecord('incident');
incr.addQuery('caused_by', chgSysID);
incr.query();
var rowCnt = incr.getRowCount();
var loopCnt = 0;
if (incr.getRowCount() > 0) {
while (incr.next()) {
loopCnt++;
// gs.info("GetChgIncidents INC: " + incr.number +" is also caused by the same.");
if (loopCnt < rowCnt)
result += incr.number + ',';
else
result += incr.number;
}
// gs.info("GetChgIncidents ressult: " + result);
}
else
result = '';
return JSON.stringify(result);
},
type: 'GetChgIncidents'
});
Try the above.