Multi Row Variable Set - Disable 'Remove All' and 'Delete' functionality (Catalog form)

Robbie
Kilo Patron
Kilo Patron

Hi,

Has anyone managed disable any of the properties and functionality associated with the new Multi Row Variable Set on the Service Catalog form? 

Specifically, I'm trying to disable the 'Remove All' option as well as the delete functionality (x icon per row). Whilst I can achieve this via DOM manipulation, obviously I'm very conscious of the unsupported nature around this.

I've tried setting UI policies for example as well as setting write roles etc, however I'm not having much success using supported approaches. Anyone else tried this?

To provide some background as to the why, we're leveraging the MRVS to present a list of Assets and asset data associated against a user and asking a user to confirm, edit and add data if required. However for anything pre-populated we want to prevent deleting or removing this data. Any data the user choses to add, this could be removed/deleted.

Thanks in advance,

Robbie

16 REPLIES 16

Simon Christens
Kilo Sage

I managed to manipulate with the variable set so either remove or show from each row but it requires some knowledge to read and understand what ServiceNow tried to do out of the box.

Ill try to explain here:

My example is:

If you are assigned to in 1 or more of the cmdb_ci_server records in the multirow variable set you are able to either approve or reject the server though the edit button.

find_real_file.png

So as a system admin i will get this:

find_real_file.png

Theres a built-in method to get the data from the variable set:

//Multirow variable set sys_id
    var varset_id = '6b4e1a52db700490b182793ebf961967';
	
	//Multirow variable set name
    var varset_name = 'new_multi';
	
	//OOB Built in data from variable sets
    var data = tableVariableCache[varset_id].rowData;
console.log(data);

 

The output will be:

Here is the data to identify each row and be able to DOM manipulate each row

find_real_file.png

So my onLoad Client script looks like this:

function onLoad() {

	//Multirow variable set sys_id
    var varset_id = '6b4e1a52db700490b182793ebf961967';
	
	//Multirow variable set name
    var varset_name = 'new_multi';
	
	//OOB Built in data from variable sets
    var data = tableVariableCache[varset_id].rowData;
	
	//sys_id if the server variable in the multirow var set
    var server_var_id = '026e9e56db700490b182793ebf96199a';
	
	//Current user
    var user_id = g_user.userID;
	
	//Remove Add and Remove all
	var set = document.getElementById('table_variable_buttons_' + varset_id);
    set.style.display = 'none';

	//Server call to get all appropiate approvers for all the given servers
    var ajax = new GlideAjax('GetServerApprovers');
    ajax.addParam('sysparm_name', 'getServerApprovers');
    ajax.addParam('sysparm_data', g_form.getValue(varset_name));
	ajax.addParam('sysparm_field_id', server_var_id);
    ajax.getXMLAnswer(function(answer) {

        var answerObj = JSON.parse(answer);

		//Loop through all rows in the data objects 
        for (var key in data) {

			//For each row we check our answer object to get the approver
            for (var server in answerObj) {

				//If the given server in the data row is the same as our server in our server obejct 
                if (answerObj[server].server == data[key].data[server_var_id].value) {

					//Grab the HTML element
                    var doc = document.getElementById('row_' + data[key].rowId);

					//If current user is not the approver in our server object then we rmeove with delete and edit buttons from the row
                    if (answerObj[server].approver != user_id) {

                        doc.getElementsByClassName('btn-sm multi-row-delete-row')[0].style.display = 'none';
                        doc.getElementsByClassName('btn icon-edit btn-sm')[0].style.display = 'none';

                    } else {

						//If the user is approver for the given row then we just remove the delete option
                        doc.getElementsByClassName('btn-sm multi-row-delete-row')[0].style.display = 'none';
                    }
                }
            }
        }
    });
}

 

The script include where i get the approvers from each server.

var GetServerApprovers = Class.create();
GetServerApprovers.prototype = Object.extendsObject(AbstractAjaxProcessor, {

    getServerApprovers: function() {

		//Get all the given servers in the multirow variable set
        var data = JSON.parse(this.getParameter('sysparm_data'));
		var server_variable_id = this.getParameter('sysparm_field_id');
        var servers = [];
		var returnValue = [];
		
		//Field that contains approvers in cmdb_ci_server
		var ownerField = 'assigned_to';
		
        for (var i = 0; i < data.length; i++) {
           
            var row = data[i];
			//Loop through each row / server
            for (var key in row) {

				//Grabs the server sys_id from the object
                if (key == server_variable_id) {

                    servers.push(row[key]);
                }
            }
        }
		
		//Get all the servers with sys_id and approver sys_id
		var serGr = new GlideRecord('cmdb_ci_server');
		serGr.addNotNullQuery(ownerField); //Owner of the server
		serGr.addQuery('sys_id', 'IN', servers.toString());
		serGr.query();
		while(serGr.next()){
			
			var obj = {};
			obj.server = serGr.getUniqueValue();
			obj.approver = serGr.getValue(ownerField);
			
			returnValue.push(obj);
		}
		
		//Return data object as string
		return JSON.stringify(returnValue);
    },

    type: 'GetServerApprovers'
});

asifnoor
Kilo Patron

Hi,

I have written an article on how you can disable the buttons in the MRVS. Kindly refer to this. 

https://community.servicenow.com/community?id=community_article&sys_id=376e4dfadb7698d0fa192183ca961...

Mark the comment as helpful if it helps.