Need to reorder widget in service operation workspace

Asha Pathak
Tera Contributor

Hello Community!

 

I have one requirement. In service operation workspace. Unassigned widget need at first place for my team work section only. Unassigned widget should not be display on my work section. 

 

AshaPathak_0-1739950898901.png

 

 Below is the code. Please help!

 

function include({
    imports
}) {
 
    class ServiceDeskLandingPageUtilsSNC {
 
        /**
         * Returns visualization configs
         * @Param {object} helpers
         * @Param {string} mode
         * @return object
         */
        static async getVisualizationConfig(helpers, mode) {
            const evamDef = this.getEvamDef();
            const visualizationConfig = [{ 
                    "id": "interaction_donut",
                    "tableName": "interaction",
                    "tableDisplayValue": "interaction",
                    "myWorkQuery": "active=true^assigned_toDYNAMIC90d1921e5f510100a9ad2572f2b477fe",
                    "myTeamQuery": "active=true^assignment_groupDYNAMICd6435e965f510100a9ad2572f2b47744",
                    "listView": mode == "your_work" ? "sow_landing_page_assigned" : "sow_landing_page",
                    "header": mode == 'your_work' ? await helpers.translate("Interaction assigned to me") : await helpers.translate("Interaction assigned to my team"),
                    "groupByField": "state",
                    "evamId": evamDef['Service Desk Interaction'],
                     "updated_on": "^ORDERBYDESCsys_updated_on",
                }, 
               {
                    "id": "incident_assigned",
                    "tableName": "incident",
                    "tableDisplayValue": "Incident",
                    "myWorkQuery": "active=true^assigned_toDYNAMIC90d1921e5f510100a9ad2572f2b477fe^state!=6",
                    "myTeamQuery": "active=true^assigned_toISNOTEMPTY^assignment_groupDYNAMICd6435e965f510100a9ad2572f2b47744^state!=6",
                    "listView": mode == "your_work" ? "sow_landing_page_assigned" : "sow_landing_page",
                    "header": mode == 'your_work' ? await helpers.translate("Incidents assigned to me") : await helpers.translate("Incidents assigned to my team"),
                    "groupByField": "state",
                    "evamId": evamDef['incidentEvamDefinitionId'],
                    "updated_on": "^ORDERBYDESCsys_updated_on",
                },
                {
                    "id": "sc_req_item",
                    "tableName": "sc_req_item",
                    "tableDisplayValue": "Requested Items",
                    "myWorkQuery": "active=true^assigned_toDYNAMIC90d1921e5f510100a9ad2572f2b477fe",
                    "myTeamQuery": "active=true^assignment_groupDYNAMICd6435e965f510100a9ad2572f2b47744",
                    "listView": 'sow_landing_page',
                    "header": mode == 'your_work' ? await helpers.translate("Catalog Items assigned to me") : await helpers.translate("Catalog items assigned to my team"),
                    "groupByField": "state",
                    "evamId": evamDef["Service Desk RITM"],
                    "updated_on": "^ORDERBYDESCsys_updated_on",
                },
                {
                    "id": "catalog_tasks",
                    "tableName": "sc_task",
                    "tableDisplayValue": "Catalog Task",
                    "myWorkQuery": "active=true^assigned_toDYNAMIC90d1921e5f510100a9ad2572f2b477fe",
                    "myTeamQuery": "active=true^assignment_groupDYNAMICd6435e965f510100a9ad2572f2b47744",
                    "listView": 'sow_landing_page',
                    "header": mode == 'your_work' ? await helpers.translate("Catalog tasks assigned to me") : await helpers.translate("Catalog tasks assigned to my team"),
                    "groupByField": "state",
                    "evamId": evamDef["catalogTaskEvamDefinitionId"],
                    "updated_on": "^ORDERBYDESCsys_updated_on",
                },
                {
                    "id": "incident_sla",
                    "tableName": "task_sla",
                    "tableDisplayValue": "Task SLA",
                    "myWorkQuery": "task.sys_class_name=incident^task.assigned_toDYNAMIC90d1921e5f510100a9ad2572f2b477fe^task.active=true^sla.type=SLA^ORsla.type=OLA^active=true^time_left<=1970-01-08 00:00:00",
                    "myTeamQuery": "task.sys_class_name=incident^task.assignment_groupDYNAMICd6435e965f510100a9ad2572f2b47744^task.active=true^sla.type=SLA^ORsla.type=OLA^active=true^time_left<=1970-01-08 00:00:00",
                    "listView": 'sow_landing_page',
                    "header": await helpers.translate("Incident SLAs"),
                    "groupByField": "time_left",
                    "evamId": evamDef['incidentSlaEvamDefinitionId'],
                    "updated_on": "^ORDERBYtime_left",
                }
/*
// This is commented by Asha  Pathak (Infocenter) as "Story Assigned to me" was not required to be visible on the Homepage 
               {
                    "id": "story_assigned",
                    "tableName": "rm_story",
                    "tableDisplayValue": "Story",
                    "myWorkQuery": "active=true^assigned_toDYNAMIC90d1921e5f510100a9ad2572f2b477fe",
                    "myTeamQuery": "active=true^assigned_toISNOTEMPTY^assignment_groupDYNAMICd6435e965f510100a9ad2572f2b47744",
                    "listView": mode == "your_work" ? "sow_landing_page_assigned" : "sow_landing_page",
                    "header": mode == 'your_work' ? await helpers.translate("Stories assigned to me") : await helpers.translate("Stories assigned to my team"),
                    "groupByField": "state",
                    "evamId": evamDef['storiesEvamDefinitionId'],
                    "updated_on": "^ORDERBYDESCsys_updated_on",
                },
*/
 ];
 
            if (mode == 'your_work' && conditionalRecordCount > 0) {
                const conditionalConfig = await this.getConditionalVisualizationConfig(helpers);
                visualizationConfig.push(conditionalConfig);
            }
 
            if (mode  != 'your_work') {
                var unassigned_incident =
                    {
                        "id": "unassigned_incidents",
                        "tableName": "incident",
                        "tableDisplayValue": "Incident",
                        "myTeamQuery": "active=true^assigned_toISEMPTY^assignment_groupDYNAMICd6435e965f510100a9ad2572f2b47744",
                        "listView": mode == "your_work" ? "sow_landing_page_assigned" : "sow_landing_page",
                        "header": await helpers.translate("Unassigned incidents"),
                        "groupByField": "priority",
                        "evamId": evamDef['incidentEvamDefinitionId'],
                        "updated_on": "^ORDERBYDESCsys_updated_on",
                    };
 
                var unassigned_interaction =
                    {
                        "id": "donut_id",
                        "tableName": "interaction",
                        "tableDisplayValue": "Interaction",
                        "myTeamQuery": "active=true^assigned_toISEMPTY^assignment_groupDYNAMICd6435e965f510100a9ad2572f2b47744",
                        "listView": mode == "your_work" ? "sow_landing_page_assigned" : "sow_landing_page",
                        "header": await helpers.translate("Unassigned interactions"),
                        "groupByField": "state",
                        "evamId": evamDef['Service Desk Interaction'],
                        "updated_on": "^ORDERBYDESCsys_updated_on",
                    };
 
         var unassigned_catalog_items =
                    {
                        "id": "sc_req_item",
                        "tableName": "sc_req_item",
                        "tableDisplayValue": "Requested Items",
                        "myTeamQuery": "active=true^assigned_toISEMPTY^assignment_groupDYNAMICd6435e965f510100a9ad2572f2b47744",
                        "listView": mode == "your_work" ? "sow_landing_page_assigned" : "sow_landing_page",
                        "header": await helpers.translate("Unassigned Catalog items"),
                        "groupByField": "state",
                        "evamId": evamDef['Service Desk RITM'],
                        "updated_on": "^ORDERBYDESCsys_updated_on",
                    };
                
                visualizationConfig.push(unassigned_incident);
                visualizationConfig.push(unassigned_interaction);
                visualizationConfig.push(unassigned_catalog_items );
            }         
            return visualizationConfig;
 
}
            
 
        /**
         * Build visualization card configurations (Donut)
         * @Param {object} helpers
         * @Param {string} mode
         * @return object
         */
        static async getDonutConfig(helpers, mode) {
            var donutConfig = [];
            var visualizationConfig = await this.getVisualizationConfig(helpers, mode);
 
            for (var i = 0; i < visualizationConfig.length; i++) {
                var obj = {};
                obj = {
                    "id": visualizationConfig[i].id,
                    "header": visualizationConfig[i].header,
                    "evamId": visualizationConfig[i].evamId,
                    "updated_on": visualizationConfig[i]["updated_on"],
                    "listView": visualizationConfig[i].listView,
                    "datasource": [{
                        "isDatabaseView": false,
                        "allowRealTime": true,
                        "sourceType": "table",
                        "label": {
                            "message": visualizationConfig[i].tableDisplayValue
                        },
                        "tableOrViewName": visualizationConfig[i].tableName,
                        "filterQuery": mode == 'your_work' ? visualizationConfig[i].myWorkQuery : visualizationConfig[i].myTeamQuery,
                        "id": visualizationConfig[i].id
                    }],
                    "metric": [{
                        "dataSource": visualizationConfig[i].id,
                        "id": visualizationConfig[i].id + "metric",
                        "aggregateFunction": "COUNT",
                        "numberFormat": {
                            "customFormat": false
                        },
                        "axisId": "primary"
                    }],
                    "groupBy": [{
                        "maxNumberOfGroups": "ALL",
                        "numberOfGroupsBasedOn": "NO_OF_GROUP_BASED_ON_PER_METRIC",
                        "showOthers": false,
                        "hideZeroValues": true,
                        "groupBy": [{
                            "dataSource": visualizationConfig[i].id,
                            "groupByField": visualizationConfig[i].groupByField,
                            "isRange": false,
                            "isPaBucket": false
                        }]
                    }]
                };
                donutConfig.push(obj);
            }
 
            return donutConfig;
        }
 
        static getEvamDef() {
            const evamDef = {
                'incidentEvamDefinitionId': '01a404e8b7203010e69dbc16de11a93f',
                'incidentSlaEvamDefinitionId': '749b857eb7283010e69dbc16de11a98d',
                'storiesEvamDefinitionId' : 'ffdebcbc1b3fad50789a4197dc4bcb83',
                'catalogTaskEvamDefinitionId': '4a59c876c7323010d7e818b1c7c26083',
'Service Desk Interaction':'2cb49e841b16ce50789a4197dc4bcbd5',
'Service Desk RITM':'38f2bb0187b75650cb567777dabb35d7',
 
 
 
                 
// Updated by Priyanka Agarwal for stories to be viewed on SOW on 03/07/2023 for Case no CASE0045980
            };
            return evamDef;
        }
 
        /**
         * Returns configuration for work persona dropdown
         * @Param {object} helpers
         * @return {object}
         */
        static async getWorkPersonaConfig(helpers) {
            return {
                "items": [{
                        "id": "your_work",
                        "label": await helpers.translate("My work")
                    },
                    {
                        "id": "your_team_work",
                        "label": await helpers.translate("My team's work")
                    }
                ],
                "defaultSelected": ["your_work"]
            }
        }
 
        static getRangeObject(query, key) {
            var ans = {}
            var queryTokens = query.split('^');
            for (var index in queryTokens) {
                var token = queryTokens[index];
                if (token.indexOf(key) == -1)
                    continue;
                token = token.replace('=', '');
                if (token.indexOf('<') != -1)
                    ans.end_value = token.substring(token.indexOf('<') + 1)
                else
                    ans.start_value = token.substring(token.indexOf('>') + 1)
            }
            return ans;
        }
 
        static async getSLAHeader(range, report_ranges, helpers) {
            for (var index in report_ranges) {
                if (range.end_value == report_ranges[index].upper_value_duration)
                    return (await helpers.translate("Incident SLA time remaining - {0}", report_ranges[index].label));
            }
            return (await helpers.translate('Incident SLAs'));
        }
 
        static getFieldMap() {
            const fieldMap = {
                'State': 'state',
                'Priority': 'priority',
                'Actual time left': 'time_left'
            };
            return fieldMap;
        }
 
        static async fetchTitleForSLA(query, reportRanges, helpers) {
            var range = this.getRangeObject(query, 'time_left');
            return (await this.getSLAHeader(range, reportRanges, helpers));
        }
 
        static async fetchTitle(table, nameValueMap, groupByLabel, groupMode = false) {
            const groupByField = this.getFieldMap()[groupByLabel];
            return this.getLabelMaps(table, nameValueMap[groupByField], groupByField, groupMode);
        }
 
       static getLabelMaps(table, selectedField, groupByField, groupMode = false) {
            const labelMap = {
                'incident': {
                    'state': {
                        '1': 'New incidents',
                        '2': 'In Progress incidents',
                        '3': 'On Hold incidents',
                        '6': 'Resolved incidents'
                    },
                    'priority': {
                        '1': 'P1 unassigned incidents',
                        '2': 'P2 unassigned incidents',
                        '3': 'P3 unassigned incidents',
                        '4': 'P4 unassigned incidents',
                        '5': 'P5 unassigned incidents'
                    }
                },
               'rm_story':{
'state':{
'-6' : 'Draft',
                                                '1' : 'Ready',
                                                 '2' : 'Work In Progress',
                                                 '-7' : 'Ready for Testing',
                                                 '-8' : 'Testing'   
}
                
            },
                'sc_task': {
                    'state': {
                        '-5': 'Pending catalog tasks',
                        '1': 'Open catalog tasks',
                        '2': 'Work in progress catalog tasks'
                    }
            },
        'interaction' : {  
            'state':{
                 '-3': 'On Hold',
                  '1': 'New',    
                  '2': 'Work in Progress'
  }
}
            };
 
            if(table == 'incident' && groupByField == 'priority')
                return labelMap[table][groupByField][selectedField];
         
   if (groupMode)
                return labelMap[table][groupByField][selectedField] + '  assigned to my team';
            return labelMap[table][groupByField][selectedField] + '  assigned to me';
 
        }   
 
        static async getVisualisationCardConfig(id, helpers, mode) {
            var visualizationConfig = await this.getVisualizationConfig(helpers, mode);
            var currentVizSelection = {};
            for (var i = 0; i < visualizationConfig.length; i++) {
                if (visualizationConfig[i].id === id) {
                    currentVizSelection.table = visualizationConfig[i].tableName;
                    currentVizSelection.query = mode === "your_team_work" ? visualizationConfig[i].myTeamQuery + visualizationConfig[i]["updated_on"] : visualizationConfig[i].myWorkQuery + visualizationConfig[i]["updated_on"];
                    currentVizSelection.evamId = visualizationConfig[i].evamId;
                    currentVizSelection.elementId = visualizationConfig[i].id;
                    currentVizSelection.title = visualizationConfig[i].header;
                    currentVizSelection.groupByField = visualizationConfig[i].groupByField;
                    currentVizSelection.listView = visualizationConfig[i].listView;
                    break;
                }
            }
            return currentVizSelection;
        }
 
        static async getVisualisationCardQuery(vizSelection, nameValueMap, helpers, mode) {
            var field = this.getFieldMap()[vizSelection.groupBy];
            var value = nameValueMap[field];
            var query = '';
            var visualizationConfig = await this.getVisualizationConfig(helpers, mode);
            for (var i = 0; i < visualizationConfig.length; i++) {
                if (visualizationConfig[i].id === vizSelection.elementId) {
                    query = mode === "your_team_work" ? visualizationConfig[i].myTeamQuery : visualizationConfig[i].myWorkQuery;
                    break;
                }
            }
            if (Array.isArray(value)) {
                for (let index in value)
                    query += '^' + field + value[index];
            } else {
                if (value.includes('='))
                    query += '^' + field + value;
                else
                    query += '^' + field + '=' + value;
            }
            return query + visualizationConfig[0]["updated_on"];
        }
    }
 
    return ServiceDeskLandingPageUtilsSNC;
}
2 REPLIES 2

Mark Manders
Mega Patron

Open the page in UI builder, remove the widget you don't want and drag the one you need in front to there.


Please mark any helpful or correct solutions as such. That helps others find their solutions.
Mark

@Mark Manders , I have created widget by using script, no by ui builder