UI Action to update multiple records from list view

mballinger
Mega Guru

Hello,

I need a UI Action that will allow a user to select 1 or many records and then open a comments dialog modal . The comments modal will update all selected records with the comment entered. How can I do this? 

***EDIT***

I've figured out how to do this through Alerts and Prompts, but I want to do this using GlideModal and UI Page. Can someone help me figure out how to reconstruct what I have?

UI Action:

function getRecords() {
    var oldVal = '';
    var selectedRecords = g_list.getChecked(); 
    var prompt = prompt("Enter a Comment Here: ", oldVal);

    if (!selectedRecords|| selectedRecords.length == 0)
        return;
    if (prompt!= '' && prompt!= null) {
        var ga = new GlideAjax('GetRecordsSelected');
        ga.addParam('sysparm_name', 'getSelectedRecords');
        ga.addParam('sysparm_ids', selectedRecords);
        ga.addParam('sysparm_prompt', prompt);
        ga.getXML(getRec);
    } else {
        alert("Please input a comment");
    }

    function getRec(response) {
        var answer = response.responseXML.documentElement.getAttribute("answer");
        location.reload();
    }
}

Script Include:

var GetRecordsSelected = Class.create();
GetRecordsSelected.prototype = Object.extendsObject(AbstractAjaxProcessor, {
    getSelectedRecords: function() {
        var array = [];
        var selectedRecords = this.getParameter('sysparm_ids');
		var prompt = this.getParameter('sysparm_prompt');
        var sysIds = selectedRecords.split(",");
        var gr = new GlideRecord('incident');
        gr.addQuery('sys_id', 'IN', selectedRecords);
        gr.query();
        while (gr.next()) {
            gr.short_description = prompt;
			gr.state = '3'; //On Hold
			gr.caller_id = 'Abel Tuter (architect)'; //Abel Tutter
			gr.assignment_group = '019ad92ec7230010393d265c95c260dd'; //Analytics Settings Managers
			gr.update();
        }
    },

    type: 'GetRecordsSelected'
});

Thanks!

1 ACCEPTED SOLUTION

use this to pass variables to your UI Page

.setPreference('your_param','test'); 

Then you can use this code to set variables

<j:set var="jvar_your_param" value="${sysparm_your_param}"/>

And reference in client script by

'${JS:sysparm_your_param}'

ServiceNow Nerd
ServiceNow Developer MVP 2020-2022
ServiceNow Community MVP 2019-2022

View solution in original post

5 REPLIES 5

bammar
Kilo Sage
Kilo Sage

You can technically already do this by update selected UI context menu,

But to do what your doing you have to investigate a UI action that opens a modal window which will be set up under UI page and would have only the comments window.

Also another trick is the control trick hold control and click all the comments boxes you want to update let go control doubleclick one of the cells then type your comments in and all cells will be updated- you may not want to recreate something you have multiple ways of doing now

Thanks for your response @bammar . There are other things that I need to update as well within this UI Action. The UI Action is intended for some of our Business users, and they are not savvy enough to figure this out. This is why we are giving them the UI Action to make their job a little more simplified

@bammar - So I figured out how to do what I needed to do using Alerts and Prompts. I want to step it up a notch using GlideModal and UI Page. How would I pass data through my UI Action to my UI Page, and then send that info to my Script Include to update selected Records? I've updated the post with my code

 

use this to pass variables to your UI Page

.setPreference('your_param','test'); 

Then you can use this code to set variables

<j:set var="jvar_your_param" value="${sysparm_your_param}"/>

And reference in client script by

'${JS:sysparm_your_param}'

ServiceNow Nerd
ServiceNow Developer MVP 2020-2022
ServiceNow Community MVP 2019-2022