How to create a UI Action that populates a List Collector without saving the record?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
I’m trying to create a UI Action on a form that will automatically populate certain values inside a List Collector field when the button is clicked.
I want the List Collector to be updated on the form only, but I do not want the record to save when the UI Action is clicked.
- the list collector updates only in the database (requires a save), or
- the form reloads and loses the populated values, or
- nothing happens at all.
- Populates a List Collector field client‑side,
- Leaves changes visible on the form,
- But does not save or submit the form automatically?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hello @NowNinja727 ,
Some of the suggestions shared are already on the right track.nYou can achieve this using a setup like the one below. It keeps everything client-side, avoids hard-coded values, and works for both new and existing records.
Just try to adjust them based on your use case...........
1. Store the values in a System Property
Instead of embedding values directly in the UI Action, store them in a configurable system property.
Example Property Name
standard_division_ids
Value (comma-separated sys_ids)
id1,id2,id3,id4,...
2. Create a Script Include (Client Callable)
The Script Include’s responsibility is only to return the sys_ids from the system property
var StandardDivisionUtils = Class.create();
StandardDivisionUtils.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getStandardDivisionIds: function() {
var value = gs.getProperty('standarddivisionids', '');
if (!value)
return '';
// Trim whitespace if any
return value.replace(/\s+/g, '');
},
type: 'StandardDivisionUtils'
});
Make sure Client callable = true.
3. Client-side UI Action (No Save, No Refresh)
UI Action configuration
-
Client: true
-
Form button: true
-
OnClick: addStandardDivisions
UI Action Script
function addStandardDivisions() {
var ga = new GlideAjax('StandardDivisionUtils');
ga.addParam('sysparmname', 'getStandardDivisionIds');
ga.getXML(function(response) {
var node = response.responseXML.documentElement;
var answer = node && node.getAttribute("answer") ? node.getAttribute("answer") : '';
if (!answer) {
g_form.addErrorMessage('No standard divisions configured.');
return;
}
// Parse sys_ids from the system property
var standardIds = answer.split(',');
// Existing list collector values
var existingValue = g_form.getValue('division_field') || '';
var existingList = existingValue ? existingValue.split(',') : [];
// Merge and de-duplicate
var merged = {};
existingList.forEach(function(x) {
if (x) merged[x] = true;
});
standardIds.forEach(function(x) {
if (x) merged[x] = true;
});
var finalValue = Object.keys(merged).join(',');
if (finalValue === existingValue) {
g_form.addInfoMessage('All standard divisions already exist.');
return;
}
// Update field on the form only (NO SAVE)
g_form.setValue('division_field', finalValue);
g_form.addInfoMessage('Standard divisions added. Review and save if needed.');
});
}
Replace division_field with the actual List Collector field or variable name.
🔹 Please mark ✅ Correct if this solves your query, and 👍 Helpful if you found the response valuable.
Best regards,
Aniket Chavan
🏆 ServiceNow MVP 2025 | 🌟 ServiceNow Rising Star 2024
