Need to create UI Action in Incident List View

1__vipind
Tera Contributor

I would like to know if we can change the state field and the date field(to the current date) in the Incident list view via UI Action without refreshing the page.

If yes! then how can we achieve the same?

 

I've created below mentioned script 

 

----------------------------------------------------------------------------------------------------------------------------

function statusupdate(){
    var stateupdate = g_list.getChecked();
        if (!stateupdate) {
        alert('Please select at least one record.');
        return;
        };
        var userConfirmed = confirm('Are you sure you want to update state and date field')
    if(!userConfirmed){
        return;
    };
    if(userConfirmed==true){
         gsftSubmit(null, g_form.getFormElement(), 'statusupdata');
    }
    if (typeof window == 'undefined')
    gs.log('this the test0');//
           function serverupdate(){
            current.state= 2;
            gs.log('this the test1');
            current.u_testing_date = new GlideDateTime();
            current.update();
           
        action.setRedirectURL(current);
           
           };
serverupdate()
   


};

 

 

2 REPLIES 2

Arun_Manoj
Mega Sage

Hi,

Step 1: Create a GlideAjax Script Include

  1. Navigate to System Definition > Script Includes.

  2. Create a new Script Include:

    • Name: IncidentStatusUpdater
    • Accessible from: All application scopes
    • Active: Checked
    • Client Callable: Checked

Add the following code to the Script Include:

 

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

updateIncidentStatus: function(incidentSysIds) {
var incidentIds = incidentSysIds.split(',');
var updatedCount = 0;
incidentIds.forEach(function(incidentId) {
var gr = new GlideRecord('incident');
if (gr.get(incidentId)) {
gr.setValue('state', 2); // Assuming 2 is the desired state value
gr.setValue('u_testing_date', new GlideDateTime());
gr.update();
updatedCount++;
}
});
return updatedCount;
},

type: 'IncidentStatusUpdater'
});

 

Step 2: Create a UI Action for the List View

  1. Navigate to System Definition > UI Actions.

  2. Create a new UI Action:

    • Table: Incident
    • Active: Checked
    • Show Insert: Unchecked
    • Show Update: Unchecked
    • List Action: Checked
    • Name: statusupdate
    • Action name: statusupdate

Add the following code to the UI Action:

 

 

function statusupdate() {
var selectedRecords = g_list.getChecked(); // Get selected records
if (!selectedRecords) {
alert('Please select at least one record.');
return;
}

var userConfirmed = confirm('Are you sure you want to update state and date fields?');
if (!userConfirmed) {
return;
}

// Call the server-side script include via GlideAjax
var ga = new GlideAjax('IncidentStatusUpdater');
ga.addParam('sysparm_name', 'updateIncidentStatus');
ga.addParam('sysparm_incidentSysIds', selectedRecords);
ga.getXMLAnswer(function(response) {
var updatedCount = response.responseXML.documentElement.getAttribute('answer');
alert(updatedCount + ' incidents updated successfully.');
g_list.refresh(); // Refresh the list view
});
}

 

Thanks

Arun

1__vipind
Tera Contributor

This code doesn't work. I've figured this out on my own .