Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Widget "My Request" in Service Portal for Watch list

Itsmehiiiiiiii
Tera Contributor

Hi All,

 

Can someone help me how can I achieve this?


To summarize my request, what they want is use the watchlist functionality in portal view so that the users without access on our backend can view it using the portal.


Then there's this request tab or button beside the user's profile and when you click it there's this dropdown called "VIEW" wherein we can see the open request and closed request that we or user created.

The requirement that they gave to me is that can we add another value on that drop down and we can call it "Closed Watch list", wherein when they select that value all of the closed tickets will be visible as long as they're part of the watch list.

As you can see on the screenshots I provided, I already apply it but under the closed watch list the title of the tickets I'm seeing is just the number of the ticket instead of the short description for incident and name of the catalog items for RITM.

I'll attached as well the default view or title display under the open request.

Thank you in advance!

1 ACCEPTED SOLUTION

Hello @Itsmehiiiiiiii, Glad that you are able to see the titles correctly.

Yes, you will get the duplicates and for the same I asked to adjust the function getMyRequestSysIds().

Nevertheless, could you please try replacing with below one. You can make any necessary adjustment in the if and else block ( your filter name or any new add query)

    function getMyRequestSysIds() {		
        var ids = {};
        var rq_filter = new GlideRecord('request_filter');
        rq_filter.addActiveQuery();
        if (rq_filter.isValidField('applies_to')){
			if (localInput && localInput.view === 'closed_watchlist'){
				rq_filter.addQuery('applies_to', 1).addOrCondition('applies_to', 10);
				rq_filter.addQuery('title', 'Watched Closed List');
			}
			else {
				rq_filter.addQuery('applies_to', 1).addOrCondition('applies_to', 10);
				rq_filter.addQuery('title','!=', 'Watched Closed List');
			}
		}
        rq_filter.query();
        while (rq_filter.next()) {
            var tableName = rq_filter.table_name;
            if (rq_filter.isValidField('table'))
                tableName = rq_filter.table;
            var gr = new GlideRecord(tableName);
            if (!gr.isValid())
                continue;

            gr.addQuery(rq_filter.filter);
			gr.enableSecurityFeature('data_filter');
            gr.query();
            if (tableName == 'sc_request')
                alsoRequest = true;
            while (gr.next()) {
                var portalSettings = {};
                portalSettings.page = rq_filter.portal_page.nil() ? '' : rq_filter.portal_page.getDisplayValue() + '';
                portalSettings.primary_display = rq_filter.primary_display.nil() ? '' : rq_filter.primary_display + '';
                portalSettings.secondary_displays = rq_filter.secondary_display.nil() ? '' : rq_filter.secondary_display + '';
                ids[gr.sys_id + ''] = portalSettings;
            }
        }
        return ids;
    }

 

Please note that I'm sharing above code without any validation, make necessary adjustment, if required.

You can create duplicate titles too in request filter like one for incident and one for Request, but if you wish to keep them different, then change the addQuery() accordingly.

 

P.S: surely, there might be better ways to filter in/out the Filter Request, but I can write above without any validation right now.

 

Regards,

Nishant 

View solution in original post

12 REPLIES 12

Hello @Itsmehiiiiiiii, Glad that you are able to see the titles correctly.

Yes, you will get the duplicates and for the same I asked to adjust the function getMyRequestSysIds().

Nevertheless, could you please try replacing with below one. You can make any necessary adjustment in the if and else block ( your filter name or any new add query)

    function getMyRequestSysIds() {		
        var ids = {};
        var rq_filter = new GlideRecord('request_filter');
        rq_filter.addActiveQuery();
        if (rq_filter.isValidField('applies_to')){
			if (localInput && localInput.view === 'closed_watchlist'){
				rq_filter.addQuery('applies_to', 1).addOrCondition('applies_to', 10);
				rq_filter.addQuery('title', 'Watched Closed List');
			}
			else {
				rq_filter.addQuery('applies_to', 1).addOrCondition('applies_to', 10);
				rq_filter.addQuery('title','!=', 'Watched Closed List');
			}
		}
        rq_filter.query();
        while (rq_filter.next()) {
            var tableName = rq_filter.table_name;
            if (rq_filter.isValidField('table'))
                tableName = rq_filter.table;
            var gr = new GlideRecord(tableName);
            if (!gr.isValid())
                continue;

            gr.addQuery(rq_filter.filter);
			gr.enableSecurityFeature('data_filter');
            gr.query();
            if (tableName == 'sc_request')
                alsoRequest = true;
            while (gr.next()) {
                var portalSettings = {};
                portalSettings.page = rq_filter.portal_page.nil() ? '' : rq_filter.portal_page.getDisplayValue() + '';
                portalSettings.primary_display = rq_filter.primary_display.nil() ? '' : rq_filter.primary_display + '';
                portalSettings.secondary_displays = rq_filter.secondary_display.nil() ? '' : rq_filter.secondary_display + '';
                ids[gr.sys_id + ''] = portalSettings;
            }
        }
        return ids;
    }

 

Please note that I'm sharing above code without any validation, make necessary adjustment, if required.

You can create duplicate titles too in request filter like one for incident and one for Request, but if you wish to keep them different, then change the addQuery() accordingly.

 

P.S: surely, there might be better ways to filter in/out the Filter Request, but I can write above without any validation right now.

 

Regards,

Nishant 

Hi @Nishant8 ,

I will test and validate it on my end. Thank you! Hope you're still around if ever I have additional question. 

Hi @Nishant8 ,

Thank you for your help. I did apply the solution you gave to me. It's now displaying the same title for closed watch list.

 

Have a great day!