How to show only specific fields in table filter on Service Portal for an end user (customer)?

Akhil Pendem
Tera Contributor

Hello,

I've a requirement to show only few fields for the end user in table filter on service portal. Can we achieve this?

find_real_file.png

 

Thanks in advance,

Akhil

11 REPLIES 11

Hi Akhil,

Implement with caution, the solution has DOM manipulation and it is highly likely to break in future version

Below is working for paris version of servicenow

Additional Client controller:

You need to inject the service snCustomEvent like below

find_real_file.png


snCustomEvent.on('snfilter:activated', startRemoving);
function startRemoving(){
		setTimeout(function(){ 	
			removeFiltersColumms(document.getElementsByClassName("field-list-button"));
			}, 3000);
	function removeFiltersColumms(elementbyclass){
		var validArray =$scope.data.validColumms;
		var validArray1 = validArray.split(",");
		var arrayObj = [];
		var fieldLists = angular.element(elementbyclass).scope().comparison.baseFields;  

		var count = Object.keys(fieldLists).length; 
		for(var i=0; i<count; i++)
		{
			var fieldname = Object.keys(fieldLists)[i];
			var columnname =fieldLists[fieldname]["name"];
 if(validArray1.indexOf(columnname) < 0 && columnname != "123TEXTQUERY321"){
arrayObj.push(columnname);
	}

		}

		for( var z= 0; z< arrayObj.length; z++){
		delete fieldLists[arrayObj[z]];
		}
		observermethod();
	}
	
	function observermethod(){
		var target = document.getElementsByClassName("compounds")[0];
var observer = new MutationObserver(function(mutations) {
    mutations.forEach(function(mutation) {
var el = document.getElementsByClassName("field-list-button");
		for(var i = 0; i< el.length; i++){
		removeFiltersColumms(el[i]); 
		}
    });
});

var config = {childList: true, subtree: true }
observer.observe(target, config);
	}

 

Server side code:

data.validColumms = "active,name";// coma separated column name or $sp.getListColumns(data.table, "your view here");

Screenshot

find_real_file.png

 

Attached the widget so you can play around with it 🙂

 

@rahulpandey  Thanks for the widget. I'll try it and will update the post accordingly.

I have similar requirement its any other way to achieve this without DOM manipulation. Please assist on that.

Hi,

 

You can restrict read access to those fields for end user. 

 

Thanks.

Hi Asha,

Thanks for the heads up. Looking forward to hearing from you! .