- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-04-2024 10:52 AM
Hello for all!!
On the Incident Form, I have to add some logic so that whenever the “Assigned to” changes, it displays a message under the field, displaying the count of how many active Incidents that user has currently assigned...
Anyone has done something similar?
Thanks
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-04-2024 11:02 AM
Hi @Servinho Deve ,
You would require an onChange client script & a client callable script include in order to achieve this.
Can u give the below code a try
Client side:
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
// Get the sys ID of the assigned user
var assignedToSysID = g_form.getValue('assigned_to');
// Make a GlideAjax call to server script to get the count of active incidents
var ga = new GlideAjax('GetActiveIncidentCount');
ga.addParam('sysparm_name', 'getActiveIncidentCount');
ga.addParam('assigned_to', assignedToSysID);
ga.getXMLAnswer(function(response) {
// Display the count of active incidents under the field
var message = 'Number of active incidents assigned: ' + response;
g_form.addInfoMessage(message);
});
}
Script Include:
var GetActiveIncidentCount = Class.create();
GetActiveIncidentCount.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getActiveIncidentCount: function() {
var assignedTo = this.getParameter('assigned_to');
// Query active incidents assigned to the user
var gr = new GlideRecord('incident');
gr.addQuery('assigned_to', assignedTo);
gr.addActiveQuery(); // Only active incidents
gr.query();
// Get the count of active incidents
var count = gr.getRowCount();
return count.toString();
}
});
Thanks,
Danish
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-04-2024 10:58 AM
You need a client script onChange of Assigned to field, to run and get the list of incidents assigned to that person. From the client script you need to make a glideajax to a script include.
In the script include you need to add logic to GlideAggregate and return you the count and then display it using Client Script.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-04-2024 11:02 AM
Hi @Servinho Deve ,
You would require an onChange client script & a client callable script include in order to achieve this.
Can u give the below code a try
Client side:
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
// Get the sys ID of the assigned user
var assignedToSysID = g_form.getValue('assigned_to');
// Make a GlideAjax call to server script to get the count of active incidents
var ga = new GlideAjax('GetActiveIncidentCount');
ga.addParam('sysparm_name', 'getActiveIncidentCount');
ga.addParam('assigned_to', assignedToSysID);
ga.getXMLAnswer(function(response) {
// Display the count of active incidents under the field
var message = 'Number of active incidents assigned: ' + response;
g_form.addInfoMessage(message);
});
}
Script Include:
var GetActiveIncidentCount = Class.create();
GetActiveIncidentCount.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getActiveIncidentCount: function() {
var assignedTo = this.getParameter('assigned_to');
// Query active incidents assigned to the user
var gr = new GlideRecord('incident');
gr.addQuery('assigned_to', assignedTo);
gr.addActiveQuery(); // Only active incidents
gr.query();
// Get the count of active incidents
var count = gr.getRowCount();
return count.toString();
}
});
Thanks,
Danish