How to popolate, how many incidents has the "assigned to".

Servinho Deve
Tera Contributor

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

1 ACCEPTED SOLUTION

Danish Bhairag2
Tera Sage
Tera Sage

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

View solution in original post

2 REPLIES 2

SanjivMeher
Kilo Patron
Kilo Patron

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.


Please mark this response as correct or helpful if it assisted you with your question.

Danish Bhairag2
Tera Sage
Tera Sage

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