How to display an info message for total tickets raised by current User on Service portal

Varsha Soni1
Tera Contributor

Hi,

Please help me to solve this requirement:  display the info message with number of incident tickets raised by current user while he opens the form to raise a new incident ticket on the service portal. 

2 REPLIES 2

Tushar
Kilo Sage
Kilo Sage

Hi @Varsha Soni1 

 

 

I think we will have to create a custom widget in Service Portal as per your requirement.

 

 

Place the widget you created on the incident creation form in Service Portal.

 

In the widget server script, you need to query the incident table to count the number of incidents raised by the current user.

 

I think you should use the GlideAggregate class for this purpose.

 

Here's an example script:

 

 

(function() {
    var user = gs.getUser();  // Get the current user's GlideUser object
    var currentUserID = user.getID();  // Get the current user's sys_id
    
    var incidentGr = new GlideAggregate('incident');
    incidentGr.addQuery('caller_id', currentUserID);  // Query incidents raised by the current user
    incidentGr.addAggregate('COUNT');  // Count the number of incidents
    incidentGr.query();
    
    var incidentCount = 0;
    if (incidentGr.next()) {
        incidentCount = incidentGr.getAggregate('COUNT');
    }
    
    data.incidentCount = incidentCount;
})();

 

 

In the widget client script, you can use the data received from the server to display the info message. Here's an example script:

 

 

 

<your-widget-name>.controller('WidgetController', ['$scope', function($scope) {
    var incidentCount = $scope.data.incidentCount;
    
    if (incidentCount > 0) {
        spUtil.addInfoMessage('You have raised ' + incidentCount + ' incident(s).');
    }
}]);

 

 

Widget HTML -

 

 

<div>
    <!-- Your widget content here -->
</div>

 

 

Please, don't forget to mark my answer as correct if it solves your issue or mark it as helpful if it is relevant for you!

Regards,
Tushar

 

Thanks Tushar for your help.