Set a default filter for userlist when adding approvers in SOW

HagosT
Tera Guru

Does anyone know how to make the list show only users with the approval role?

OOTB all users are listed.


HagosT_1-1777900345530.png


There seem to be a possility to set a fixed filter but don't understand how.
We want all users to have a default filter that shows only users with approval role.

Add approvers.png



2 ACCEPTED SOLUTIONS

HagosT
Tera Guru

The final solution:

We’ve implemented a custom extension point override (best practice) to control the “Add Approver” selection in Service Operation Workspace. 

 

Result:
The picker now only shows:

* Active users
* Users with role approver_role
* Users not already assigned as approvers

 

Approach:

* Used extension point RelatedListItemCandidateFilter with key APPROVER_QUERY_FILTER
* Added a custom Script Include that returns a filtered query


New Class: CustomRelatedListApproverItemCandidateFilter

HagosT_0-1777984349835.png

View solution in original post

HagosT
Tera Guru
var CustomRelatedListApproverItemCandidateFilter = Class.create();
CustomRelatedListApproverItemCandidateFilter.prototype = {
initialize: function(tableName, parentFieldName, parentRecordSysId, referencedFieldName) {
this.tableName = tableName;
this.parentFieldName = parentFieldName;
this.parentRecordSysId = parentRecordSysId;
this.referencedFieldName = referencedFieldName;
},

getFilterQuery: function() {

// --- Existing approvers (exclude them) ---
var existing = [];
var gr = new GlideRecord(this.tableName);
gr.addQuery(this.parentFieldName, this.parentRecordSysId);
gr.query();
while (gr.next()) {
existing.push(gr.getValue(this.referencedFieldName));
}

// --- Users with approval_user role ---
var roleUsers = [];
var rel = new GlideRecord('sys_user_has_role');
rel.addQuery('role.name', 'approver_user');
rel.addQuery('user.active', true);
rel.query();
while (rel.next()) {
roleUsers.push(rel.getValue('user'));
}

// --- Build query ---
var query = 'active=true';
if (existing.length > 0)
query += '^sys_idNOT IN' + existing.join(',');
if (roleUsers.length > 0)
query += '^sys_idIN' + roleUsers.join(',');
else
query += '^sys_id=NULL'; // prevent showing all users
 
return query;
},

handles: function(thing) {
return thing == 'APPROVER_QUERY_FILTER';
},

type: 'CustomRelatedListApproverItemCandidateFilter'
};

View solution in original post

7 REPLIES 7

meghanakra
Kilo Guru

Show only users who have the approver_user role (or any approval-related role) in a reference field/list.

field is roles and the value is approver_user

please try it.

roles=approver_user

 

Maham Tahir
Mega Guru

Hi @HagosT

 

You can use the UI Builder to configure the "SOW Associate Record Modal". Here are the steps:

  1. Navigate to the UI Builder.

  2. In the "Page" dropdown, select "SOW Record page modals".

  3. In the "Variant" dropdown, select "SOW Associate Record Modal".

  4. At the bottom of the page, click on "Data" to open the data resources panel.

  5. Click "+ Add" and select "Client state".

  6. Configure the new client state parameter as follows:

    • Name: approverFilter

    • Type: String

    • Initial value: roles=approver_user

  7. In the "Data" panel, under "Local data resources", select "List Controller".

  8. In the "Configuration" section of the List Controller, locate the "Fixed filter" field.

  9. Click the "@" symbol to open the data binding modal.

  10. From the "Client state" section, drag and drop the approverFilter you created into the "Fixed filter" field.

  11. Click "Apply" and then "Save" to apply the changes.

This will apply a default filter to the user list in the "Add approvers" modal, showing only users who have the approver_user role.

 

If you find my response helpful, mark it as helpful and accepted solution.

 

Regards, 

Maham Tahir.

Tanushree Maiti
Mega Patron

Hi @HagosT 

 

You can customize to get expected result by addition of role ,filter etc.

 

refer: Service Operations Workspace (SOW) - List view configuration

 KB0994285 List view in Custom Workspace in not loading for non admin users 

 

Please mark this response as Helpful & Accept it as solution if it assisted you with your question.
Regards
Tanushree Maiti
ServiceNow Technical Architect
Linkedin:

Ankur Bawiskar
Tera Patron

@HagosT 

which form has this screenshot?

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