Excerpt |
---|
|
The Use formula as a separate column or as an aggregation option within other column types. You can input formula inside embedded JavaScript Editor and get results on the grid view. The grid can process formula logic and aggregate display formula results. |
This page describes formulas functionality in the Table Grid Editor for Jira Cloud.
A Formula is a separate column type based on JavaScript. Add a separate column using formula column type, input formula inside embedded JavaScript Ace Editor and get results on the grid. The grid can process formula logic and aggregate formula results.
You can add a formula as a separate column in a grid by selecting the formula column type. The column uses JavaScript to create formulas.
Formula expressions - editor, where you can input JavaScript formula code. It uses Ace Editor, which highlights the syntax.
Info |
---|
title | Error types in the formula column type |
---|
|
You can get the error as a result of the formula execution using following error types: |
You can use formula as an aggregation operation in other columns.
It provides you the flexibility to operate grid data in different ways.
This feature is available for all column types, supported by the Table Grid Next Generation for Jira Cloud.
In order to display formula result in the grid column input JS expression in the formula expression configuration.
You can do following operations using formulas:
string concatenation;
mathematical operations with numbers: addition, subtraction, multiplication, division;
date subtraction - it's possible to use Moments.js library;
conditions
- userlist operation
You can create a formula using JavaScript. The column ID is a variable, use it in the following format: $(yourColumnId).
Use return as a keyword to get the formula result.
Note |
---|
|
Use the following example to display Userlist column type in the formula Code Block |
---|
language | js |
---|
theme | Eclipse |
---|
title | Userlist in formula |
---|
| return $(user).value |
|
Code Block |
---|
language | js |
---|
theme | Eclipse |
---|
title | String concatenation |
---|
collapse | true |
---|
|
return $(firstStringColumnId) + ' ' + $(secondStringColumnId); |
Code Block |
---|
language | js |
---|
theme | Eclipse |
---|
title | Numbers operations |
---|
collapse | true |
---|
|
//Numbers and Integer column type
return $(numb1) * $(numb2) return $(numb1) / $(numb2) return $(numb1) + $(numb2) return $(numb1) - $(numb2) return Math.abs() |
Code Block |
---|
language | js |
---|
theme | Eclipse |
---|
title | Checkbox condition |
---|
collapse | true |
---|
|
if($(check) || $(role) === 'Team lead'){ return $(numb1) * $(numb2) } else { return $(numb1) / $(numb2) / 0 } |
Code Block |
---|
language | js |
---|
theme | Eclipse |
---|
title | Using variables with date and moment.js library |
---|
collapse | true |
---|
|
firstDate = moment($(firsdt));
var secondDate = moment($(seconddt));
var difference = firstDate.diff(secondDate);
return Math.abs(moment.duration(difference).asDays()); |
Below you can find formula examples with most common expressions.
This example shows how to provide exam results, based on the conditions specified in the formula. You can use conditions in the formula with all available column types.
Code Block |
---|
language | js |
---|
theme | Eclipse |
---|
title | Condition formula expression |
---|
|
var correctPercent = $(correct) * 100 / $(total)
var result = ''
if($(level) === 'low') {
result = correctPercent > 60 ? 'Passed' : 'Fail'
} else if ($(level) === 'medium') {
result = correctPercent > 70 ? 'Passed' : 'Fail'
} else {
result = correctPercent > 80 ? 'Passed' : 'Fail'
}
return result |
This example shows how to subtract Date. You can use Date, Time, DateTime column types.
Code Block |
---|
language | js |
---|
theme | Eclipse |
---|
title | Date subtraction using Moments.js formula expression |
---|
|
var firstDate = moment($(startDate));
var secondDate = moment($(endDate));
var difference = firstDate.diff(secondDate);
return Math.abs(moment.duration(difference).asDays()); |
This example shows how to use checkbox column type in condition formula.
Code Block |
---|
language | php |
---|
theme | Eclipse |
---|
title | Checkbox formula expression |
---|
|
if($(calculate)){
return $(salary) + $(bonus)
} else {
return $(salary)
} |
This example shows how to use JavaScript Math.
Code Block |
---|
language | js |
---|
theme | Eclipse |
---|
title | Numbers using JS Math operations formula expression |
---|
|
var sum = $(a) + $(b)
if(sum > 1000) {
return sum * $(coefficient)
} else {
return sum / $(coefficient)
} |
This example shows how to concatenate string column type.
Code Block |
---|
language | js |
---|
theme | Eclipse |
---|
title | String Concatenation expression |
---|
|
return $(user) + ' ' + $(position) |