Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

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

Siri Namamula
Tera Contributor

Hi @mballinger 

 I have a similar requirement can you provide all the changes you made to achieve this it will be very helpful