Related list filter

shalurajeev
Tera Contributor

Hello All,

 

I have a custom object u_order_form. I have a m:m relationship between this custom object and alm_license using the junction table u_order_license. order_id in u_order_license connects to u_order_form and lic_id in u_order_license connects to alm_license table. I have a form view with a record from u_order_form on top and OOTB related list showing records from the junction table - u_order_license. This related list has a OOTB New button that allows me to associate more licenses to the order form. I want to add a filter to this process -when the form view for adding a new license opens and user clicks on the License field (lic_id reference field to alm_license table) it should only bring up list of licenses that are not already associated with the parent order. I tried creating a new relationship from  System Definition -> Relationships but I'm not able to add this as a related list to my form view as a related list (not sure why).  I need advice for the following -

 

1. Is this approach of using Relationships the right away? If not what are the alternate approaches?

2. Why am I not being able to see this new Relationship as a related list when I try to configure and add it to my form layout from the custom object view?

3. Below is the query I used in my relationship. Is this correct?

(function refineQuery(current, parent) {
    var ga = new GlideAggregate('u_order_license');
    ga.addQuery('order_id', parent.sys_id);
    ga.query();

    var excludeProducts = [];
    while (ga.next()) {
        excludeProducts.push(ga.lic_id.toString());
    }

    if (excludeProducts.length > 0) {
        current.addQuery('sys_id', 'NOT IN', excludeProducts.join());
    }
})(current, parent);
 
Thanks
 
3 REPLIES 3

Ankur Bawiskar
Tera Patron
Tera Patron

@shalurajeev 

which table is selected in "Applies to table" ? That table's form will have that related list

Why not use this?

1) reference qualifier

2) dynamic filter

No need to create defined relationship for M:M tables.

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

nityabans27
Giga Guru

Hi @shalurajeev ,
For defining relationship you do not need to manually develop relationship using scripting. U can directly use related list for this purpose which you will get in configure-> related lists.

 

If you find my answer useful please mark it helpful and accept it as solution.

Thanks and regards
Nitya Bansal

AnkitS27
Tera Contributor

To define a relationship between tables, you don't need to write custom scripts manually. Instead, you can simply use the Related Lists feature available through Configure → Related Lists, which allows you to easily establish and manage relationships directly from the UI.