Display active assigned incidents count under the 'Assigned to' filed.

Ashish Routray1
Tera Contributor

On change of "Assigned to" field, display information about active assigned incidents count of corresponding agent selected under the "Assigned to" field.

1 ACCEPTED SOLUTION

No problem. Happy to help, please mark as correct if you can.

View solution in original post

10 REPLIES 10

Brian Lancaster
Tera Sage

Need more information. Is the requirement to keep info there and up to date? Or is it just a temporary display that only shows when a incident is assigned?

yeah brian requirement to keep info there and up to date

 



Whenever "Assigned to' field populated with a new agent, active assigned incidents count should be displayed as a info message under the 'Assigned to' field.

Message should be cleared, if "Assigned to" field is empty.

No message should appear after updating the incident record.

Dan H
Tera Guru

Hi,

Here is a example I tested on my PDI.

When the assigned to value changes on the incident, the new selected user's assigned to incidents are counted up and will be alerted on the screen.

You can change the alert to whatever you need to do with the value.

 

Script include Name: getAssignedToCount

 

var getAssignedToCount = Class.create();
getAssignedToCount.prototype = Object.extendsObject(AbstractAjaxProcessor, {

	getAssignedTo: function(){ 
		var assignedTo = this.getParameter('sysparm_assignedto');
		var incidentGA = new GlideAggregate('incident');
		incidentGA.addQuery('assigned_to', assignedTo);
		incidentGA.addAggregate('COUNT');
		incidentGA.query();
		if(incidentGA.next()){
		incidentGA.next();
		var json = new JSON();
		var count = incidentGA.getAggregate('COUNT');
		return JSON.stringify(count); 
		}else{
		return null;
		}
		
		},
	
	
    type: 'getAssignedToCount'
});

 

Client Script (onChange -> Assigned to field)

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

   var rec = new GlideAjax('getAssignedToCount');
  rec.addParam('sysparm_name', 'getAssignedTo');
  rec.addParam('sysparm_assignedto', newValue);
  rec.getXML(populateData);

  // When the response is back from the server
  function populateData(response) {
    var answer = response.responseXML.documentElement.getAttribute('answer');
    var result = JSON.parse(answer);
    alert('Total assigned incident count for this user: ' + result);
  }
}

 

Hope this helps.

Please mark my answer as Correct/Helpful based on impact

Regards,

Dan H