Need to create UI Action in Incident List View
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-22-2024 03:11 AM
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
----------------------------------------------------------------------------------------------------------------------------
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-22-2024 03:16 AM
Hi,
Step 1: Create a GlideAjax Script Include
Navigate to System Definition > Script Includes.
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
Navigate to System Definition > UI Actions.
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-25-2024 02:35 AM
This code doesn't work. I've figured this out on my own .