Quantcast
Channel: Cloud Sherpas » Valor Poland
Viewing all articles
Browse latest Browse all 11

Tech Tuesdays: ServiceNow: Creating Custom-Defined Relationships

$
0
0

Every once in a while, I get a request to add a “Related List” for items that are not direct relationships within ServiceNow. One little-known (and underutilized) feature of ServiceNow is custom-defined relationships.

Here are a few use requests that we often receive:

  • Show all fields that exist on a given form, across all form sections (this is a part of our Administration EXCELerator)

  • On a Change Request, show a combined list of Incidents AND Problems (and Incidents related to those problems)

  • Add a list of notifications (and allow a new one to be created) from an Event Registry entry

I’m one of the ServiceNow Discovery Implementation Specialists, so in this post, we’ll take a look at how to show recent ECC queue entries for a given MID Server.

This is a classic problem: I’m looking at my MID Server list, and one is down, so I want to know the last transaction it processed. I could go to the ECC transaction queue and try to search/filter, but I could bring the data into my context — MID Server form I’m currently looking at.

In order to set this up, we need to go find the query that will result in the correct list.

Here you see that I’ve filtered to “Topic != HeartbeatProbe>Topic does not contain queue.>Agent = mid.server.CloudSherpas-MID1″, and this is where we want to start.

Let’s Right-Click on the last breadcrumb and “Copy query.”

I end up with:

topic!=HeartbeatProbe^topicNOT LIKEqueue.^agent=mid.server.CloudSherpas-MID1

The next thing we need to do figure out how to make this dynamic.

My MID Server name is “CloudSherpas-MID1,” so in looking at my MID Server record, I see that in the “Name” field.

This brings us to our missing link: the Relationship entry.

Let’s navigate to System Definition > Relationships and open a new form.

Here are the important parts of our form:

  1. Name: what should we call our new related list?

  2. Applies to table: where do we want our new related list to be available?

  3. Queries from table: what kind of records should we display?

  4. Query with: the code to run against the database to return the correct result set

So now that we know what the fields mean, here’s how I’ve filled out my form:

You’ll notice that in the “Query with” field, I did nothing more than copy & paste what we filtered to earlier. Why go to all the hard work to re-filter, breadcrumb by breadcrumb in code, when I can just paste it in?

The only update I made was to replace the hard-coded MID server name, and make this query dynamic. As a result, we can infer that these two objects are available:

  • current: the query being run (“Queries from table”)

  • parent: the form where this related list is showing (“Applies to table”)

Here, I’ve simply grabbed the “name” of the MID Server record I’m looking at, and appended it to the end of my query.

Now, let’s save it, and add it to our form, and see how it works.

Excellent! We now have a short list of the most recent transactions that particular MID Server has processed.

Since the ECC Queue table on a busy instance can get very sizable very quickly, we need to make sure we put a reasonable default filter on it. Here, I’ve set a “Created on Today” filter as the default. You also may want to Personalize > the List Control and turn off the buttons (you see the “new” button here), depending on your particular use.

In summary, when you need a related list that’s indirect (or in our case a text-match, instead of a sys_id-match), grab a pen and paper, draw out the tables (and the columns) that contain the relationship, and filter away!

The post Tech Tuesdays: ServiceNow: Creating Custom-Defined Relationships appeared first on Cloud Sherpas.


Viewing all articles
Browse latest Browse all 11

Trending Articles