Need to populate all the incident's number in a custom field based on logged in user.

Feroz1
Tera Contributor

Hi Team,

 I need all the incident number which are assigned to logged in user, and all the incident's it should be populated in of the custom field.

Please help me with solution. Thanks in advance.

3 ACCEPTED SOLUTIONS

Sumanth16
Kilo Patron

Hi @Feroz1 ,

 

var comm =[];
var perInc = new GlideRecord('incident');
perInc.addQuery('opened_bt,gs.getUserID());
perInc.query();
while(perInc.next()){
comm.push(perInc.number.toString());
}

perc.u_personal_comments = comm.toString();//change the field name

If I could help you with your Query then, please hit the Thumb Icon and mark it as Correct !!


Thanks & Regards,
sumanth Meda

View solution in original post

Community Alums
Not applicable

Hi @Feroz1 ,

 

You can create BR (can be at When: Display), with the script below:

(function executeRule(current, previous /*null when async*/ ) {

    var arr = [];
    var inc = new GlideRecord('incident');
    inc.addQuery('assigned_to', gs.getUserID());
    inc.query();

    while (inc.next()) {
        arr.push(inc.sys_id.toString());
    }
    if (arr.length) {
        current.u_count = arr.toString(); // replace u_count with your custom field's name
    }

})(current, previous);

View solution in original post

Amit Gujarathi
Giga Sage
Giga Sage

HI @Feroz1 ,
I trust you are doing great.
Please find below code for the same:

var GetUserIncidents = Class.create();
GetUserIncidents.prototype = {
    initialize: function() {
    },

    getIncidentsForCurrentUser: function() {
        var currentUser = gs.getUserID(); // Get the sys_id of the current user
        var incidentList = []; // Initialize an array to hold the incident numbers

        var gr = new GlideRecord('incident'); // Query the incident table
        gr.addQuery('assigned_to', currentUser); // Filter incidents assigned to the current user
        gr.query();
        while (gr.next()) {
            incidentList.push(gr.getValue('number')); // Add the incident number to the array
        }

        return incidentList; // Return the array of incident numbers
    },

    type: 'GetUserIncidents'
};

Was this answer helpful?


Please consider marking it correct or helpful.


Your feedback helps us improve!


Thank you!


Regards,


Amit Gujrathi



View solution in original post

3 REPLIES 3

Sumanth16
Kilo Patron

Hi @Feroz1 ,

 

var comm =[];
var perInc = new GlideRecord('incident');
perInc.addQuery('opened_bt,gs.getUserID());
perInc.query();
while(perInc.next()){
comm.push(perInc.number.toString());
}

perc.u_personal_comments = comm.toString();//change the field name

If I could help you with your Query then, please hit the Thumb Icon and mark it as Correct !!


Thanks & Regards,
sumanth Meda

Community Alums
Not applicable

Hi @Feroz1 ,

 

You can create BR (can be at When: Display), with the script below:

(function executeRule(current, previous /*null when async*/ ) {

    var arr = [];
    var inc = new GlideRecord('incident');
    inc.addQuery('assigned_to', gs.getUserID());
    inc.query();

    while (inc.next()) {
        arr.push(inc.sys_id.toString());
    }
    if (arr.length) {
        current.u_count = arr.toString(); // replace u_count with your custom field's name
    }

})(current, previous);

Amit Gujarathi
Giga Sage
Giga Sage

HI @Feroz1 ,
I trust you are doing great.
Please find below code for the same:

var GetUserIncidents = Class.create();
GetUserIncidents.prototype = {
    initialize: function() {
    },

    getIncidentsForCurrentUser: function() {
        var currentUser = gs.getUserID(); // Get the sys_id of the current user
        var incidentList = []; // Initialize an array to hold the incident numbers

        var gr = new GlideRecord('incident'); // Query the incident table
        gr.addQuery('assigned_to', currentUser); // Filter incidents assigned to the current user
        gr.query();
        while (gr.next()) {
            incidentList.push(gr.getValue('number')); // Add the incident number to the array
        }

        return incidentList; // Return the array of incident numbers
    },

    type: 'GetUserIncidents'
};

Was this answer helpful?


Please consider marking it correct or helpful.


Your feedback helps us improve!


Thank you!


Regards,


Amit Gujrathi