Skip to Content

Bulk Update Selected Records

Add a list button to update multiple selected records at once with custom logic.

List Button Table: incident
#ui-action #list-button #bulk-update #client #glideajax

Script Code

JavaScript
1// Client-side code
2function bulkUpdateRecords() {
3  // Get selected records
4  var selected = g_list.getChecked();
5
6  if (selected.length === 0) {
7    alert('Please select at least one record');
8    return;
9  }
10
11  // Confirm action
12  var confirmed = confirm('Are you sure you want to update ' + selected.length + ' record(s)?');
13  if (!confirmed) {
14    return;
15  }
16
17  // Show loading message
18  var loadingMsg = 'Updating ' + selected.length + ' record(s)...';
19  g_list.addInfoMessage(loadingMsg);
20
21  // Make server call to process records
22  var ga = new GlideAjax('BulkUpdateProcessor');
23  ga.addParam('sysparm_name', 'processBulkUpdate');
24  ga.addParam('sysparm_record_ids', selected.join(','));
25  ga.addParam('sysparm_table', 'incident');
26
27  // Add update parameters (customize these)
28  ga.addParam('sysparm_field', 'state');
29  ga.addParam('sysparm_value', '2');  // In Progress
30
31  ga.getXMLAnswer(function(response) {
32    if (response) {
33      var result = JSON.parse(response);
34
35      if (result.success) {
36        g_list.addInfoMessage('Successfully updated ' + result.updated + ' record(s)');
37        g_list.refresh();
38      } else {
39        alert('Error: ' + result.message);
40      }
41    }
42  });
43}

How to Use

1. Create a new UI Action on your table 2. Set Name to "Bulk Update" 3. Set Table to "incident" (or your table) 4. Check "List button" checkbox 5. Check "Client" checkbox 6. Set Order: 100 7. Paste the code above in the Script field 8. Create the BulkUpdateProcessor Script Include (server-side handler) 9. Test by selecting multiple records in a list

Explore More Scripts

Browse our complete library of ServiceNow scripts

View All Scripts