Pranshu5
Giga Contributor

Problem Statement

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 Configure Related Lists. 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.

Comments
Asmita7
Tera Expert

Hello Pranshu,

 

Thank you very much for the important and useful information.

 

I have used this code and it is working ang creating Filter condition on "sys_m2m_template.do" form.

But this filter condition is editable for end users.

I want to make these Filter condition as  "Read Only".

 

How to achieve it ?

 

Thank you,

Rashmi Panigrah
Tera Explorer

@Asmita7  Were you able to make filter conditions read-only?

Jose Santos Alv
Tera Contributor

I want to make them read only as well

Medi C
Giga Sage

@Asmita7@Rashmi Panigrah@Jose Santos Alv:
You can add the following line to do not display the filter option:

uri.set('jvar_no_filter', 'true');
Version history
Last update:
‎04-26-2020 08:42 AM
Updated by: