FujiForty - Form Charts (advanced conditions)

There was a recent question on my first Form Charts post regarding advanced conditions. Since it's not really documented I did some experimenting.

In the last example I used a simple report filter, show the "All Incidents by Category" report where the incident location is equal to the current form's incident location. Using this form chart interface limits you to a direct field mapping (location = current.location). 

 

If you require a more advanced condition such as an OR condition you'll have to jump over to the "Advanced condition extension". It's great that there's a tab but it's not really clear on how to use it. Hovering over a field label occasionally provides some help. In this case there's just enough to get us started, assuming you already know about advanced reference qualifiers.

 

If you aren't familiar with reference qualifier scripts check out the wiki. Basically you need to provide an encoded query string (e.g. 'active=true'). Since you'll most likely want to reference information from the current form, you'll need to evaluate a script. Just like in business rule scripts, the "current" object is available and represents the current GlideRecord of the form being viewed. 

In order to evaluate a script from the 'Report qual' input, we need to use the 'javascript:' prefix. We can either provide the full script to evaluate in this field or make a call to a script include if we need more space.

Here's an example defining a query for active incidents that have the same location as the current incident's location OR the incident's caller has the same location as the current incident's location.

 

Ok, so what about the notation for these encoded query strings that the script needs to return? I always cheat by using a little shortcut from list filters.

To get the syntax for the above condition, I would first filter a list of incidents using a selected location as a place holder.

Once we run the filter we can steal the encoded query from the list breadcrumb context menu.

Here's the copied filter:

active=true^location=dc83fa500a0a0a65018ac8fb978a72b9^ORcaller_id.location=dc83fa500a0a0a65018ac8fb978a72b9

Since the sys_id values are associated with our placeholder location, we'll need to replace them with the current form's location reference. 

javascript:"active=true^location=" + current.location + "^ORcaller_id.location=" + current.location

Using the list filter shortcut allows you to easily build complex or nested conditions and retrieve the associated encoded query syntax.