My approval widget sorting

VJ4
Giga Expert

I have had to make some modifications to the approvals widget so instead of showing only the unapproved tickets, I'm having to show the closed ones as well.

What I need to implement is, for instance, if I limit the pool to 10 and if a user has 3 unapproved tickets it will show those at the top followed by the 7 most recent approved tickets. I managed to get the list to sort by the date a ticket was opened by adding gr.orderBy('sys_created_on'); but I want to also filter for 'active' tickets so if a user has any unapproved tickets they will display at the top? I was wondering if this is doable and if someone could shed some light?

var gr = new GlideRecord('sysapproval_approver');

  1. gr.setLimit(10);
  2. gr.orderBy('sys_created_on');

Thanks in advance.

1 ACCEPTED SOLUTION

Oh!


I see.


You can use the
gr.orderByDesc() multiple times and that way set more than one column to sort by



gr.orderByDesc('column_A')


gr.orderByDesc('column_B')


gr.orderByDesc('column_C')






Guessing that solves you problem right ?


View solution in original post

9 REPLIES 9

Thanks again, Stewe - that seems to have fixed the issue!!



gr.orderByDesc('state');


gr.orderByDesc('sys_created_on');


Hi @Stewe Lundin , Good day!

 

can you suggest me where to add this 'gr.orderByDesc('column_A')'  in server script of my tasks widget on ESC portal?

 

Regards,

Tejaswi G

Need a bit more than this to go on but 
I would suggest some where in between your 
var gr = new GlideRecord('your_table');
and
gr.query();

But @Stewe Lundin, in the 'HRM To dos Summary' widget they didn't glide 'sysapproval_approver' table at all. How to add this query to that?

 

I don't want to add sort options to it. Just want to display new approvals on the top followed by old approvals.

Is there any way to achieve this please, let me know.

 

Here is the server script of the widget which is used by 'My tasks" on ESC Portal.

(function() {
    //Check if current task is survey
    data.isTaskSurvey = false;
    var filters = $sp.getParameter('filters');
    data.selectedFiltersFromTodoPage = [];
    if (input && input.action == 'checkTaskType'){
        var gr = new GlideRecordSecure(input.table);
        if (gr.get(input.sysId) && gr.hr_task_type == 'take_survey')
            data.isTaskSurvey = true;
    } if(input && input.action == 'addNotification' && new GlidePluginManager().isActive('sn_lp')) {
        var pulseUtils = new sn_lp.PulseUtilsAjax();
        data.taskInfo = pulseUtils.checkForTriggeredConditions ? pulseUtils.checkForTriggeredConditions(input.table, input.taskId) : {};
    }

    // translated text
    data.i18n = {
        DELEGATED: gs.getMessage("Delegated"),
        DELEGATED_BY: gs.getMessage("Delegated by: {}")
    };

    data.isMobile = gs.isMobile();
    data.todoSummaryLeftPanel = true;
    data.todosToShow = {
            recordsToShow : {},
            recordWatchers : []
    };
    data.watchers =[];
    data.async = (input && input.onTicketPage) ? false : true;

    var util = new sn_hr_sp.todoPageUtils();
    data.tabs = util.getTabs();
    data.defaultTab = data.tabs[0].name;
    data.queryLimit = todoPageUtils.QUERY_LIMIT;

    data.todosFilters = $sp.getWidget('todos-filters', {});

    data.txt = {
        empty: {},
        onComplete: gs.getMessage('All tasks are Complete'),
        title: gs.getMessage('My tasks'),
        breadcrumb: gs.getMessage('My tasks')
    };
    data.txt.empty[data.defaultTab] = {
        title: gs.getMessage("You don't have any tasks right now.")
    };

    data.txt.empty.completed = {
        title: gs.getMessage("You don't have any completed tasks yet.")
    };

    if (input && input.action == "loadFromTicketPage") {
        data.todosToShow.recordsToShow = util.splitInTabs(new sn_hr_sp.hr_PortalUtil().processRecordsForSummary(input.recordsToShow), data.defaultTab);
        data.todosToShow.recordWatchers = input.recordWatchers;
        data.watchers = data.todosToShow.recordWatchers||[];
        data.onTodoPage = false;
        data.onTicketPage = true;
        data.parentCaseId = input.parent;
        data.activitySetName = input.activitySetName;
        data.activitySetId = input.activitySetId;
        data.selectedTodo = input.todoSelected;
        data.currentTodoIndex = (data.todosToShow.recordsToShow[data.defaultTab] && data.todosToShow.recordsToShow[data.defaultTab].length > input.currentTodoIndex) ? input.currentTodoIndex: 0;
        data.hideTodoSummary = input.hideTodoSummary;
    } else if (input && input.action == "loadTodos") {
        data.onTodoPage = true;
        data.onTicketPage = false;
        if(input.tab){
            data.tab = input.tab;
        } else{
            data.tab = data.defaultTab;
        }
        if(input.selectedFiltersFromTodoPage){
            data.todosToShow = util.getMyTodos(data.queryLimit, [], input.includeTodo,undefined,undefined,input.selectedFiltersFromTodoPage.finalFilterConditions,input.selectedFiltersFromTodoPage.applyFilters,data.tab);
        } else{
            data.todosToShow = util.getMyTodos(data.queryLimit, [], input.includeTodo,undefined,undefined,undefined,undefined, data.tab);
        }

        data.watchers = data.todosToShow.recordWatchers||[];
    } else if (input && input.action == "loadFilteredTodos") {
        data.selectedFiltersFromTodoPage = util.fetchSelectedFilters(input.filtersData);
        data.onTodoPage = true;
        data.onTicketPage = false;
        data.todosToShow = util.getMyTodos(data.queryLimit, [], input.includeTodo,undefined,undefined,data.selectedFiltersFromTodoPage.finalFilterConditions,data.selectedFiltersFromTodoPage.applyFilters);
        data.watchers = data.todosToShow.recordWatchers||[];
    } else if (input && input.action == "insertOrUpdateTodoRecord") {
        var noOfRecords = Math.ceil(input.currentCount/data.queryLimit)*data.queryLimit;
        if(noOfRecords < (todoPageUtils.QUERY_LIMIT*2))
            noOfRecords = todoPageUtils.QUERY_LIMIT*2;
        data.onTodoPage = true;
        data.onTicketPage = false;
        data.newTodosList = util.getMyTodos(noOfRecords,undefined,undefined,undefined,undefined,data.selectedFiltersFromTodoPage);
    } else if (input && input.action == "loadMoreTodos") {
        data.todosToShow = util.getMyTodos(data.queryLimit,input.excludeList,undefined,undefined,undefined,input.selectedFiltersFromTodoPage.finalFilterConditions,input.selectedFiltersFromTodoPage.applyFilters);
    } else if (input && input.action == "loadFillerTodos"){
        data.fillerTodosList = util.getMyTodos(input.fillerCount, input.fillerExcludeList,undefined,undefined,undefined,data.selectedFiltersFromTodoPage.finalFilterConditions,data.selectedFiltersFromTodoPage.applyFilters);
    }

    Object.keys(data.todosToShow.recordsToShow).forEach(function(tab) {
        (data.todosToShow.recordsToShow[tab] || []).forEach(function(todo) {
            if (!todo.displayValueList) return;
            todo.displayValueList = todo.displayValueList.map(function (displayValue) {
                return GlideSecurityUtils.escapeScript(displayValue);
            });
        });
    });

    if (data.onTicketPage) {
        data.txt.empty[data.defaultTab].message = gs.getMessage('All tasks are Complete');
    }

})();
 
Regards,
Tejaswi G

Hello @Tejaswi Gundu ,

 

Please let me know if you have configured this. I have the same requirement. Can you please help me with this?

 

Thanks in advance!