Reference Qualifier for a related list

John Prahn
Kilo Contributor

Hello, 

I am trying to use a reference qualifier on a related list. The related list is pointing to a custom table, joined together by many-to-many table. I am trying to limit the results on the related list by ensuring that we have the same company on our profile. I have tried using the information in this article: 

https://community.servicenow.com/community?id=community_question&sys_id=76200761db98dbc01dcaf3231f9619f4

However I have not been successful. The biggest question is which field on the custom table do I add the attribute. 

Any help is appreciated. Also if there is another way, I will look into that too. 

 

Thank you

1 ACCEPTED SOLUTION

Ahh I see. My apologies. You'll need to add one more line of code under the vendor query that looks like this:

 

current.addQuery('m2m.m2m_table.m2m_field', parent.sys_id);

 

except replace m2m_table with your m2m definition's many to many table, and replace m2m_field with your m2m definition's to field (which I'm assuming would be configuration_item)

 

Do you have access to your m2m definition? Type sys_m2m.list in the filter navigator to get a list of your definitions.

View solution in original post

9 REPLIES 9

Kerry10
Giga Expert

Hi John,

 

It sounds like you may not need a reference qualifier. If you are just trying to add a filter to a related list, you can do that by defining a relationship. 

  1. Go to system definition --> relationships --> new
  2. Name it what you would like
  3. applies to table = table of the form that the list should appear on
  4. queries from table = your custom table that the list displays
  5. in the query with section, add a filter as needed. for example:

    (function refineQuery(current, parent) {

         //add a query to the list using fields from the parent record with the format parent.field_name
         current.addQuery('company', parent.company);


    })(current, parent);

  6. Save
  7. return to the form > configure > related lists. You should now see this new relationship in the slush bucket.

Let me know if you have any questions or if I'm not understanding your requirements correctly.

 

Thank you Kerry. 

 

We have M2M table setup connecting the custom table to our cmdb_ci table. We have it set this way for a few reasons, mainly reporting. 

The goal is that while we are on the cmdb_ci table, we want the related list from our custom table to return results that only match our company. 

This is what I have so far regarding the relationship that you mentioned:  

find_real_file.png

Understood.  A couple of questions:

1) Is the 'company' field you're referring to the one on the cmdb_ci table?

2) Is the 'vendor' field you're referring to on the u_additions table, or the u_m2m_configurations table?

 

I believe you'll want to set the following:

Applies to table: cmdb_ci

Queries from table: whichever is the answer to question 2 above

 

Lastly, you'll want to edit the list configuration. But first let me know if this works for you and if you are able to add the related list.

 

 

 

 

The vendor field is on the u_additions table. I have tried setting it up to where the query applies to the cmdb_ci table and queries from the u_additons table. However the related list that's on the cmdb_ci table was created when we established the m2m relationship.