logo

NJP

Personalize Option for Service Portal List

Import · Nov 14, 2018 · article

Personalize option on service portal list view is one of the common ask from various customers. I have create a widget which adds a feature to allow end users to add or remove columns from list view on service portal.

Widget to add personalize feature(gear icon) on servicenow Portal list view ( Download XML from Github)

alt text

Add below html code to your Data Widget's html

 <span class="glyphicon glyphicon-cog" ng-click="c.personalize('personalize_list')" aria-hidden="true"></span>

Add below services to client controller

$rootScope, spModal, $window

Add below code to your Data Widget's client controller

$rootScope.$on('personalizationDone', function(event,data) {
        $window.location.reload(); // refresh to new layout
        });
 c.personalize = function(widgetId, widgetInput) {
        spModal.open({
            title: 'Personalize List Columns',
            widget: widgetId, 
            widgetInput: $scope.data.personalizeParms || {}
        }).then(function(){
                    $rootScope.$emit('saveChosen');

        })      
    }

Add below code to your Data Widget's Server Side code

function CheckPreference(table, view){
    var userPref = new GlideRecord('sys_user_preference');
        userPref.addQuery('name', table+'_'+view+'_list.view');
        userPref.addQuery('user', gs.getUserID());
        userPref.query();
        if (userPref.next()) {
return userPref.value;
        }
}
data.fields_array = data.fields.split(',');

Above line changes to below

data.fields_array = CheckPreference(data.table, data.view).split(',') || data.fields.split(',');

Add below code to your Data Widget's Server Side code

var personalizeObj = {};
    personalizeObj.table = data.table;
    personalizeObj.view = data.view;
    data.personalizeParms = personalizeObj;

Import Attached UI script and Widget

View original source

https://www.servicenow.com/community/developer-articles/personalize-option-for-service-portal-list/ta-p/2325699