How to create a related list

ty_roach
Tera Guru

I was trying to follow the example for creating a related list using this wiki article:

http://wiki.servicenow.com/index.php?title=Creating_Defined_Related_Lists

...but I'm not having any luck. Here's what I've done:

I created a table (u_my_table) that I want to appear as a related list to change_request. NOTE - I did not extend change_request table when creating "u_my_table", I just created it from scratch - a very simple table with minimal fields.

In u_my_table, I created a reference field (u_change) that references the change_request table. Next, I created a relationship ("System Definition -> Relationships") called "Related Change Info" with the following fields sets:

Applied to Table: change_request
Queries from Table: u_my_table

What do I need to put in the "Query with" area to ensure that only the rows I create by pressing the "New" UI Action button on the "u_my_table" related list associated with a change_request record show up for this change_request record and not every change request record. Thus far, my experiments have yielded results that either show the same u_my_table record entry in every change_request related list area or in none of them.

8 REPLIES 8

ty_roach
Tera Guru

okay...I just figured it out. I just added:

current.addQuery('u_change',parent.sys_id);


richard_selby
Kilo Guru

On the Problem form, I want to see a related list showing every CI affected by the Problem from child incidents. This is not the same as the CI attached to the Problem record itself, so creating a new relationship is the way to go, as per this wiki article
http://wiki.servicenow.com/index.php?title=Creating_Defined_Related_Lists

The field on the Problem is number (inherited from task), and in Incident it's called problem_id. They should match up.
But I'm stuck with the line of code in the Query with section to tie the Problem to the Incidents

I've tried

Name: Incident CIs Affected by Problem
Applies to Table: Problem
Queries from table: Incident
Query with:
current.addQuery('problem_id', parent.number);

When I personalise the Related Lists from the Problem view, I can choose Incident CIs Affected By Problem, it's just there's nothing in it.

I also tried switching it round like so:
current.addQuery('number', parent.problem_id);

And that displays every incident in the related list!

Can anyone figure out the magic script line to make this work?


'problem_id' is a reference field containing a record sys_id value. Number is a completely different field containing the number that you see in lists, etc. You need to match on sys_id instead. Something like this should work better.

current.addQuery('problem_id', parent.sys_id);


Thanks very much, that's perfect.
Yes, obvious in hindsight. I tend to think of the ProblemID as the real number, but of course its the sys_id.
Cheers