Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Checked Incident Records are not assigned to Current logged-in User, On click "List Banner Button"

MihirG
Tera Contributor

UI Action

Name: Assign to Me

Table: Incident [incident]

Active: checked
 
Show insert: checked
 
Show update: checked
 
Client: checked
 
List v2 Compatible: checked
 
List banner button: checked
 
OnClick: updateAssignedto()
 
function updateAssignedto() {
    var checkedRec = g_list.getChecked();
    if (checkedRec != '') {
        var ga = new GlideAjax('AssignedtoCheck');
        ga.addParam('sysparm_Recordcheck', 'incidentAssignedto');
        ga.addParam('sysparm_sysIDs', checkedRec);
        ga.getXMLAnswer(callback);

        function callback(res) {
            alert('response:'+res);
            if (res) {
                alert('Updated the Assigned to Successfully');
            }
        }
    } else {
        alert('Please select atleast one record');
    }
}
Script Include:
 
var AssignedtoCheck = Class.create();
AssignedtoCheck.prototype = Object.extendsObject(AbstractAjaxProcessor, {
    incidentAssignedto: function() {
        var checkedRecords = this.getParameter('sysparm_sysIDs');
        var record = checkedRecords.split(',');

        var storesys = '';
        for (var i = 0; i < record.length; i++) {
            var gr = new GlideRecord('incident');
            if (gr.get(record[i])) {
                gr.assigned_to = gs.getUserID();
                if (storesys !='') {
                    storesys += ',' + gr.update();
                } else {
                    storesys = gr.update();
                }
            }
        }
        return storesys;
    },
    type: 'AssignedtoCheck'
});
When clicking the ‘Assign to me’ button in the Incident Table list view, the ‘assigned to’ field does not get updated. If anyone can provide assistance with this issue, I would greatly appreciate it. Thank you.
2 ACCEPTED SOLUTIONS

Rohit99
Mega Sage

Hi @MihirG,

You may try with the following script in UI Script Section.

 

function countAllSelectedIncident() {
 
    selSysIds = g_list.getChecked(); // here you will get checked incident sys ids
    sysIdList = selSysIds.split(','); //here you will get sys id after splitting 
    numSel = sysIdList.length; // number of incidents which you selected
 
    for (i = 0; i < numSel; i++) {
        var gr = new GlideRecord('incident');
        gr.addQuery('sys_id', sysIdList[i]);
        gr.query();
 
        if (gr.next()) {
            gr.assigned_to = g_user.userID;
            gr.update();
        }
}
}
Screenshots :
 
Rohit99_0-1723188359303.png

 

Rohit99_1-1723188747876.png

 

Rohit99_2-1723188921650.png

 

 

 

 

Please mark my response as correct and helpful if it helped solved your question.

 

Thanks,

Rohit Suryawanshi

 

View solution in original post

Neeraj31
Mega Sage

Hello @MihirG ,

 

There is one small mistake in your code. When we call the Script include, we have to pass the function name in 'sysparm_name' variable. Please rename your variable name from 'sysparm_Recordcheck' to 'sysparm_name' and it will work.

 

ga.addParam('sysparm_name''incidentAssignedto');

 

Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

View solution in original post

2 REPLIES 2

Rohit99
Mega Sage

Hi @MihirG,

You may try with the following script in UI Script Section.

 

function countAllSelectedIncident() {
 
    selSysIds = g_list.getChecked(); // here you will get checked incident sys ids
    sysIdList = selSysIds.split(','); //here you will get sys id after splitting 
    numSel = sysIdList.length; // number of incidents which you selected
 
    for (i = 0; i < numSel; i++) {
        var gr = new GlideRecord('incident');
        gr.addQuery('sys_id', sysIdList[i]);
        gr.query();
 
        if (gr.next()) {
            gr.assigned_to = g_user.userID;
            gr.update();
        }
}
}
Screenshots :
 
Rohit99_0-1723188359303.png

 

Rohit99_1-1723188747876.png

 

Rohit99_2-1723188921650.png

 

 

 

 

Please mark my response as correct and helpful if it helped solved your question.

 

Thanks,

Rohit Suryawanshi

 

Neeraj31
Mega Sage

Hello @MihirG ,

 

There is one small mistake in your code. When we call the Script include, we have to pass the function name in 'sysparm_name' variable. Please rename your variable name from 'sysparm_Recordcheck' to 'sysparm_name' and it will work.

 

ga.addParam('sysparm_name''incidentAssignedto');

 

Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!