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
4 hours 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 hours ago
@NowNinja727
why this requirement? you want just value to change but not to be saved?
You can use g_form.setValue() in client side UI action and see if that works
If your UI action is server side then after setting the value using current object, unless the values are saved to database it won't reflect
💡 If my response helped, please mark it as correct ✅ and close the thread 🔒— this helps future readers find the solution faster! 🙏
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 hours ago
- reads the current values from the list collector with g_form.getValue('<list_collector_name>')
- merges in the 14 division sys_ids
- calls g_form.setValue('<list_collector_name>', finalValue)
- returns false to prevent the form submit
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 hours ago
Hi @NowNinja727 ,
Make sure you are providing comma-separated list of sys_ids in finalValue in string format
function AddToWatchlist(){
g_form.setValue("watch_list", "6816f79cc0a8016401c5a33be04be441,432c7325931721100143ad44246a4db5,62826bf03710200044e0bfc8bcbe5df1");
}
Thanks
Anand
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 hours ago
Hi @NowNinja727,
Please ensure the following:
- Your script include is "Client Callable"
- The function on your script include should query and return a string of sys ids (comma separated) (No update required)
Sample Script:getRecords: function() { // Retrieve the parameter var parm = this.getParameter('sysparm_parametername'); // If no parameter is provided, return an empty string if (!parm) { return ""; } var results = []; // Query the table var gr = new GlideRecord("YOUR_TABLE"); // Retrieve the records gr.addQuery("COLUMN=" + parm); gr.query(); while(gr.next()){ results.push(gr.getValue("sys_id")) } return results.join() }, - Your UI Action has "Client" checked and the OnClick field has the name of the function to be called.
Example: OnClick()
Here is a sample function:function onClick(){ var param = g_form.getValue("FIELD"); if(!param){ return; } var ga = new GlideAjax('YOUR_SCRIPT_INCLUDE'); ga.addParam('sysparm_name', 'getRecords'); ga.addParam('sysparm_parametername', param); ga.getXML(updateLC); } function updateLC(){ var answer = response.responseXML.documentElement.getAttribute("answer"); if(answer){ g_form.setValue(answer); } }
If this does not help, please share more details / some screenshots to check further.
Thanks & Best regards,
Medi
