Context Filter
The context filter allows you to select the correct segment of your data source based on issue values.
This is useful when you want to build a dependency between two fields or have a single Json for all issues and need a specific part of that data. The context filter helps you drill down to the entry that you need information from.
Context filters are available in:
Search Field
Info Panel
Dependant Field
Before reading this document you should understand the JSONPath basics
Available Issue Values
The values are contextual variables that allow you to filter your data source based on issue based variables.
Issue Key:
$.issue.key
Issue Id:
$.issue.id
Project Key:
$.issue.fields.project.key
Project Name:
$.issue.fields.project.name
Custom field - Text:
$.issue.fields.customfield_10XXX
Custom field - Select list:
$.issue.fields.customfield_10XXX.value
Custom field - Cascading list child:
$.issue.fields.customfield_10XXX.child.value
Custom field - Asset field:
$.issue.fields.customfield_10XXX[0].originId
Organizations - Jira Service Management -
$.issue.fields.customfield_10XXX[0].name
Assignee Account Id:
$.issue.fields.assignee.accountId
Creator User Key:
$.issue.fields.creator.key
Creator Display Name:
$.issue.fields.creator.displayName
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:
$.user.accountId
Email Address:
$.user.emailAddress
Warning: This field will be empty for most users due to GDPR compliance. Possible workaround in the FAQsDisplayName:
$.user.displayName
Active:
$.user.active
User Groups:
$.user.groups.items[*].name
Application Roles:
$.user.applicationRoles.items[*].name
Mapping eMail to accountID for a userpicker
To set a native Jira userpicker you need to know the accountID of the user you want to select. To map an email that comes from your data source to an accountID you can use the following function:
{ GET_ACCOUNT_ID_BY_MAIL(( 'mail@mail.com' )) }
{ GET_ACCOUNT_ID_BY_MAIL(( $.mydata.mail )) }
Alternative if empty of missing
If you want to handle empty or missing context fields use the ||
operator.
$.issue.fields.customfield_10555 || $.issue.fields.customfield_10777 || 'a default value'
This expression will try to get a value from the customfield 10555. If this field is empty or does not exist at the issue it will fallback to the customfield 10333 and if that field is empty a well it will fallback to a default value
Syntax Examples
$.userList[?(@.role=='Owner')]
$.userList[?(@.role=='{$.user.groups.items[0].name}')]
$.userList[?(@.name=='{$.user.displayName}')]
$.userList[?(@.id=='{$.issue.fields.customfield_10XXX}')]
$.userList[?(@.role=='{$.issue.fields.customfield_12345 || $.issue.fields.customfield_65432}')]
$.userList[?(@.role=~{ REGEX_IN_ARRAY(( $.user.groups.items[*].name )) })]
{ REGEX_MATCH(($.issue.fields.customfield_10XXX 'regexPatternToMatch')) }
{ REGEX_GROUP_MATCH(($.issue.fields.customfield_10XXX 'patternWithGroupMatch' '1')) }
{ JOIN(($.issue.fields.customfield_10XXX[*].value ',' )) }
{ QUOTED_JOIN
(($.issue.fields.customfield_10XXX[*].value ',' )) }
{ GET_ACCOUNT_ID_BY_MAIL(( $.mail )) }
{ STRIP_HTML(( $.myValueWithHTML )) }
{ DECODE_HTML(( $.myValueWithHTML )) }
{ STRIP_HTML(( DECODE_HTML(( $.myValueWithHTML )) )) }
Regex Examples
$.userList[?(@.role=~/(Owner)/g)]
This will return all results containing the word Owner
$.userList[?(@.role=~/(Owner|Admin)/g)]
This will return all results containing the word Owner
or Admin
$.userList[?(@.role=~/^((?!Admin).)*$/g)]
This will return all results not containing the word Admin
JsonPath AND / OR syntax
In rare cases you want to select multiple values at the same time by using AND &&
or OR ||
.
$.userList[?(@.id==1 || @.id==2)]
The result of this filter would be the users with id 1 and 2.
$.userList[?(@.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.
Null Values
To allow null
values in fields you can put the ?
in front of the expression. This will not fail in case of empty or missing values. This is mostly useful when you want to send empty values to your data source in case of a missing value.
?$.nullable
Examples Explained
In the following we will use a data source with this Json result:
{
"userList": [
{
"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 $.userList
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
$.userList[*]
Step 2
filter by role Owner in a static (not variable) way
$.userList[?(@.role=='Owner')]
Step 3
the expression is final after replacing Owner with the issue based variable {$.issue.fields.customfield_10020}
$.userList[?(@.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 $.userList
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
$.userList[*]
Step 2
filter by role Owner in a static (not variable) way
$.userList[?(@.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.
$.userList[?(@.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
$.userList[?(@.role=~{REGEX_IN_ARRAY(($.user.groups.items[*].name))})]
The expression above will render
$.userList[?(@.role=~/(Owner|Employee)/ig)]