How to Add an "On Behalf of Me" Filter to Display Tickets Created for Others

zee15
Tera Contributor

Hi,

I am working on a scenario where I need to add an additional filter called "On Behalf of Me", which should display all tickets that were created by me on behalf of other users on my ticket page in service portal.

Please refer to the screenshot below for reference.

zee15_0-1790055527982.png

 

Could someone help me understand how this filter can be created? Also, are any widget-level changes required to achieve this? If yes, could you please point me to the exact widget and the specific area where the changes need to be made?

Thank you in advance for your help.

1 ACCEPTED SOLUTION

Sandesh Powar
Kilo Sage

Hi @zee15 ,

You can achieve this by customizing the My Requests widget in Service Portal. The requirement is to display requests created by the currently logged-in user on behalf of other users.

Here is how you can implement it.

Step 1: Clone the My Requests widget

  1. Navigate to Service Portal → Widgets.

  2. Search for My Requests.

  3. Open the OOB widget.

  4. Clone the widget and name it My Requests - Custom.

  5. Make your changes only in the cloned widget to preserve OOB functionality.

Step 2: Update the HTML Template

Locate the existing View dropdown in the HTML Template.

Find:

<select ng-model="c.viewFilter"
        id="view"
        class="form-control adjust-width"
        ng-change="c.changeView()"
        ng-options="item.key as item.value for item in c.filterOptions">
</select>

No structural HTML changes are required because the dropdown is already dynamically populated through the Client Controller.

Step 3: Update the Client Controller

Locate the existing c.filterOptions array.

Add one additional option:

c.filterOptions = [
    {
        key: 'open',
        value: c.data.messages.openRequests
    },
    {
        key: 'close',
        value: c.data.messages.closedRequests
    },
    {
        key: 'on_behalf',
        value: 'On Behalf of Me'
    }
];

The new option will now appear in the View dropdown.

Step 4: Update the Server Script

This is the most important part.

In the Server Script, locate the existing function:

function getMyRequestSysIds() {
    // Existing OOB logic
}

After this function, add a separate function to retrieve requests created by the logged-in user for other users.

// Custom function: Get requests created on behalf of others

function getOnBehalfRequestSysIds() {

    var ids = {};

    var ritm = new GlideRecordSecure('sc_req_item');

    ritm.addQuery('request.opened_by', gs.getUserID());
    ritm.addQuery('requested_for', '!=', gs.getUserID());
    ritm.addNotNullQuery('request');

    ritm.query();

    while (ritm.next()) {

        var requestId = ritm.getValue('request');

        ids[requestId] = {};

    }

    return ids;
}

Explanation:

  • request.opened_by: Identifies the user who submitted the request.

  • requested_for: Identifies the user for whom the request was submitted.

  • gs.getUserID(): Returns the currently logged-in user's sys_id.

  • requested_for != gs.getUserID(): Excludes requests submitted for the logged-in user.

Step 5: Modify the Request Retrieval Logic

Find the existing code:

var myRequestMap = getMyRequestSysIds();
var taskIDs = Object.keys(myRequestMap);

Modify it as follows:

var myRequestMap;

if (input && input.view == 'on_behalf') {

    myRequestMap = getOnBehalfRequestSysIds();

    alsoRequest = true;

} else {

    myRequestMap = getMyRequestSysIds();

}

var taskIDs = Object.keys(myRequestMap);

This ensures that the widget uses the custom query when the user selects On Behalf of Me, while retaining the original OOB logic for other views.

Step 6: Update the Active/Closed Filter Logic

In the existing GlideRecord query, locate:

if (input && input.view === 'open')
    gr.addActiveQuery();
else if (input && input.view === 'close')
    gr.addQuery('active', 0);
else
    gr.addActiveQuery();

Modify it to:

if (input && input.view === 'open') {

    gr.addActiveQuery();

} else if (input && input.view === 'close') {

    gr.addQuery('active', 0);

} else if (input && input.view === 'on_behalf') {

    // Display both open and closed requests.

} else {

    gr.addActiveQuery();

}

Apply the equivalent condition in the search query section as well, so searching works with the new filter.

Step 7: Replace the widget on the Portal Page

  1. Open Service Portal Designer.
  2. Navigate to your Requests page.
  3. Remove the existing My Requests widget instance.
  4. Drag your cloned My Requests - Custom widget onto the page.
  5. Save the page.

When the user selects On Behalf of Me, the widget should display requests submitted by the logged-in user for other users.

Important: This example is for catalog requests using the sc_request and sc_req_item tables. The Requested For field on the RITM should be populated correctly. Also, if a single REQ contains multiple RITMs for different users, the widget will display the parent REQ if at least one RITM matches the condition.

SandeshPowar_0-1793707444555.pngSandeshPowar_1-1793707463414.png

 

SandeshPowar_2-1793707480446.png

 


Hope this helps! If this resolves your issue, please mark the response as helpful and accept it as the solution.

Regards,
Sandesh Powar
ServiceNow Rising Star

View solution in original post

7 REPLIES 7

Ankur Bawiskar
Tera Patron

@zee15 

see this

Customizing the "My Requests" Widget in Service Po... - ServiceNow Community

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

Hi @Ankur Bawiskar the same steps mentioned in the link you provided, but it's still not working. I'm not sure how or from where I can access this filter in the my-request-V2 widget.

Please see the screenshots below for reference.

zee15_1-1793704234931.png

 

zee15_2-1793704291623.png

 

Could you please help me identify what I might be missing?

Thanks.

Dinesh Chilaka
Mega Sage

@zee15 ,

Yes Adding a new filter will require customization of OOB widget named as 'My Requests' .

You need to clone that widget and do customizations.

Refer this thread to do customizations for that widget My Requests Widget Customizations 

If my response helped, mark it as helpful and accept the solution.

 

Thanks,

Dinesh

Hi @Dinesh Chilaka,

it seems this solution is for an older version of ServiceNow. The script has changed now, but I somehow managed to add the filter to the choice list. However, the filter is not working as expected.
zee15_0-1793704012146.png