Context Filter
The context filter enables you to extract the relevant segment of your data source by utilizing contextual information such as issue fields or user values.
This feature is particularly useful when you need to establish a dependency between two fields or when you have a single JSON data block for all issues and need a specific section of that data. The context filter helps you navigate to the entry that contains the information you require.
Availability
Context filters are available in the following field configurations of the app:
Search Field
Info Panel
Dependant Field
Prerequisites
Before using the context filter feature, you should have a good understanding of
Available Issue Values
The values are contextual variables that allow you to filter your data source based on issue based variables such as:
Issue Key |
|
Issue Id |
|
Project Key |
|
Project Name: |
|
Custom field - Text |
|
Custom field - Select list |
|
Custom field - Cascading list child |
|
Issue Type - Name |
|
Issue Type - Id |
|
Issue Status - Name |
|
Issue Status - Id |
|
Asset field (External Assets Platform) |
|
Organizations - Jira Service Management |
|
Assignee Account Id |
|
Creator User Key |
|
Creator Display Name |
|
See more detailed availability matrix here.
Context Filter Examples for Issue Values
Comparing number values without quotation
$.result[?(@.id=={$.issue.fields.customfield_10XXX})]
Comparing string values with quotation
$.result[?(@.name=='{$.issue.fields.customfield_10XXX}')]
Comparing against a custom field with fallback. More Information
$.result[?(@.name=='{$.issue.fields.customfield_12345 || $.issue.fields.customfield_65432}')]
Available User Values (Only in Search Field and Info Panel)
Some fields allow you to use variables about the current user and filter based on that information.
Account Id |
|
Email Address |
This field will be empty for most users due to GDPR compliance. Possible workaround in the FAQs |
DisplayName |
|
Active |
|
User Groups |
|
Application Roles |
|
See more detailed availability matrix here.
Context Filter Examples for User Values
Compare against the current users name
$.result[?(@.name=='{$.user.displayName}')]
Compare against the current users first group name
$.result[?(@.role=='{$.user.groups.items[0].name}')]
Compare against multiple values at the same time by using regular expressions
$.result[?(@.groupName=~{ REGEX_IN_ARRAY(( $.user.groups.items[*].name )) })]
Available Expression Functions
The following functions can be used to modify the data within the expression enclosed by curly brackets {}
. You can find more detailed descriptions of these functions in the documentation's expression or function section:
|
|
|
|
|
|
|
|
|
|
|
Regex Explained
$.result[?(@.role=~/(Owner)/g)]
This will return all results containing the word Owner
$.result[?(@.role=~/(Owner|Admin)/g)]
This will return all results containing the word Owner
or Admin
$.result[?(@.role=~/^((?!Admin).)*$/g)]
This will return all results not containing the word Admin
JsonPath AND | OR
In rare cases you want to select multiple values at the same time by using AND &&
or OR ||
.
$.result[?(@.id==1 || @.id==2)]
The result of this filter would be the users with id 1 and 2.
$.result[?(@.role=='Owner' && @.id==2)]
The result of this filter would be empty because no user with the id 2 and the role of an owner exists.
Step by Step Explanation of a Context Filter
In the following we will use a data source with this Json result:
{
"result": [
{
"id": 1,
"role": "Owner",
"name": "Mario Speedwagon",
"username": "mario"
},
{
"id": 2,
"role": "Employee",
"name": "Anna Sthesia",
"username": "anna"
},
{
"id": 3,
"role": "Owner",
"name": "Gail Forcewind",
"username": "gail"
}
]
}
and a custom fields:
customfield_10020 => contains role
Select Multiple Users by Role
In this example we look at all objects in $.result
and select only those elements that have the role we want equal to the content of customfield_10020. See the following 3 steps to create a complex JsonPath based on issue values.
Step 1
select all users first
$.result[*]
Step 2
filter by role Owner in a static (not variable) way
$.result[?(@.role=='Owner')]
Step 3
the expression is final after replacing Owner with the issue based variable {$.issue.fields.customfield_10020}
$.result[?(@.role=='{$.issue.fields.customfield_10020}')]
The result of this filter will be
[
{
"id": 1,
"role": "Owner",
"name": "Mario Speedwagon",
"username": "mario"
},
{
"id": 3,
"role": "Owner",
"name": "Gail Forcewind",
"username": "gail"
}
]
Select Users by Context Groups
In this example we look at all objects in $.result
and select only those elements that have the role based on the groups of the current user. See the following steps to create a complex JsonPath based on user values.
Step 1
select all users first
$.result[*]
Step 2
filter by role Owner in a static (not variable) way
$.result[?(@.role=='Owner')]
Step 3
introduction a context expression after replacing Owner with the user based variable {$.user.groups.items[0].name} which select the first group the current user is in.
$.result[?(@.role=='{$.user.groups.items[0].name}')]
Step 4
To show all users based on all groups instead of only the first one we use the following expression
$.result[?(@.role=~{REGEX_IN_ARRAY(($.user.groups.items[*].name))})]
The expression above will render
$.result[?(@.role=~/(Owner|Employee)/ig)]