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

Ankur Bawiskar
Tera Patron
Tera Patron

@Itsmehiiiiiiii 

I see OOTB there is no Closed Watch list in that view.

Did you customize that?

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Hello, yes I did customize it

@Itsmehiiiiiiii 

since you customized the widget then something is breaking and hence it's not rendering correctly

what debugging did you do?

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Hello Ankur,

Yes, this widget is a customized version.

For debugging, I double-checked the server script to verify where the display values are coming from. I tried updating the logic that sets the record.display_field, since for the “Closed Watchlist” view I need to display different details depending on the record type (e.g., Incident → short description, number, priority; RITM → catalog item name, REQ number, requested for).

However, even after adjusting that section, I’m still only getting the short description value for most records, and it doesn’t match how the default widget displays combined information for RITMs and Incidents.

Is there a recommended way to check or replicate how the default “My Requests” widget constructs its display field values? Or could the issue be with how my custom record.display_field is being bound in the HTML template?

 

Any idea about this? It would be really helpful!

 

Thanks