SlightlyLoony
Tera Contributor

find_real_file.pngHave you ever wished you could display a related list, but you couldn't figure out how to do it because the things you wanted to list were not related in the usual way (as either a related list or as a many-to-many list)? I recently had this happen to me, and I'd like to share the (easier than I expected!) solution.

find_real_file.pngThe starting point for me was the desire to show a list of CIs that a particular business service depended on. This would be a list of the CIs such as those that show up on the example Business Service Map shown at left (click to enlarge). All of those CIs are related to the parent business services through a web of relationships, not as related lists or many-to-many lists.

So how could I get something that looked like a related list, but shows the CIs that appear on the Business Service Map?

find_real_file.pngThe key trick involved is a feature called Defined Related Lists, which provides a way for you to use any method you'd like to generate a related list. I got here by clicking System Definition → Relationships. At right you can see the screen I used to create a Depends On defined related list for my purposes. The only tricky bit of code in there is the gatherIDs() function, which traverses the web of relationships recursively. There's one piece of that function that's worth understanding in detail: the if (...) statement followed by a continue statement. That little bit of code is just checking to see if we've seen a particular CI before, and if so, it skips the recursive exploration. This is a "cycle stopper" a common feature of web (aka networks) traversal — it's there to prevent circular references from recursing infinitely.

find_real_file.pngOnce I created this defined related list, I just went to a business service, right-clicked and chose Personalize → Related List, and I could see that the defined related list I had just created showed up in the list of available related list under the name I gave it. I just selected and added Depends On as a new related list. Voila! My new list showed up, just as you can see at left.

5 Comments
Mark Stanger
Giga Sage

I just wrote an article on this exact same topic today :). Check out this article for some more tips and some useful defined related lists that you won't see out-of-box.

http://www.servicenowguru.com/system-definition/relationships/defined-related-lists/


dbhertel
Tera Contributor

SlightlyLooney -- once again, you've hit the nail on the head. Just this week were discussing the need to provide a capability just like this. A very common request by Service owners.... 'show me just my stuff!'

I just gave your example a shot and it worked perfectly. Outstanding! Thank you very much for reading our apparently-looney-minds! 🙂


dave_m13
Kilo Contributor

Hi

This is excellent and is something very similar to what I require, however I want to do it from a Change, so if a Service/Location/CI selected then it will show a list of all related CI's exactly how you have.

So as a test I created your relationship, however it does not seem to work for me, it returns all my CI's. Obviously I have done something wrong. It complains that there are missing { in 2 places, however if I add these then complains it cannot reach ids[id] = true; after continue.

Any assistance to get your relationship part working and then doing the same on a change would be appreciated

var ids = {};
gatherIDs(parent.getUniqueValue(), ids);
var id_arr = [];
for (var id in ids)
id_arr.push(id);
current.addQuery('sys_id', id_arr);

function gatherIDs(ci_id, ids) {
var gr = new Gliderecord('cmdb_rel_ci');
gr.addQuery('parent', ci_id);
gr.query();
while (gr.next()) {
var id = '' + gr.child;
if (ids[id])
continue;
ids[id] = true;
gatherIDs(id, ids);
}
}


cdeclos
Mega Contributor

Some application modules are not dedicated to company-wide use, but are restricted to some user groups. I tried to create a mtom relationship between the sc_category_group_mtom and the sys_app_module table (see attached screenshot), but it doesn't seem to work: when trying to add a group to the 'available for group' related list, the selection window remains empty.

Did I miss something, somewhere ? I guess so... But what ?
mtom.jpg


jamesrcarroll
Kilo Explorer

This was very insightful! I wish I could see the images though. They are not displaying. I did something similar using CIUtils2.