logo

NJP

Control Filter Conditions in Edit button slushbucket on M2M table Related List

Import · Apr 26, 2020 · article

We have created a M2M table relating Hardware Assets and Requested Item. End user can add multiple hardware assets to the Requested Item based on a HAM Catalog Item. But the 'Edit...' button slushbucket should have some filter conditions auto-applied based on the Catalog Item, to reduce the selection list of hardware assets for end user.

Solution

Configure personalized Edit button for the Related List by creating a new UI Action. Use the Script field to set particular query required on slushbucket.

Explanation Steps

1. Created M2M relationship with 2 reference fields : from-Requested Item(sc_req_item) & to-Hardware Asset(alm_hardware)

2. Click the Requested Item form context menu icon and select . Using the slushbucket, select the 'Hardware Assets' related list to display on the form.

[We have added UI Policy Related List Action to limit the Related List visibility only on HAM related Requested Items]

3. Create a new 'Edit...' UI Action for 'Hardware Assets M2M Requested Items' table

[Can reference Global > Edit... button]

Condition:

(new GlideRecord(current.getTableName())).canCreate() && RP.isRelatedList() && !RP.getListControl().isOmitEditButton()

Script:

var uri = action.getGlideURI();
var path = uri.getFileFromPath();
uri.set('sysparm_m2m_ref', current.getTableName());
uri.set('sysparm_stack', 'no');

//Create query
var query = uri.get('sysparm_query');
if (query)
    query = query + '^';
//For Deploy catalog Item
if (parent.cat_item.toString() == 'bfb3af7fdb041450ba86abc5ca96194b') {
    //State = In stock & Substate = Pending disposal
    query = 'install_status=6^substatus=pending_disposal';
}
uri.set('sysparm_query', query);

action.setRedirectURL(uri.toString('sys_m2m_template.do'));

In the script,parent = the record on which Related List is added (Ex- Requested Item).

parent.variables = can also use Requested Item variables' values against Hardware Asset table fields.

View original source

https://www.servicenow.com/community/developer-articles/control-filter-conditions-in-edit-button-slushbucket-on-m2m/ta-p/2321542