...
The script copies Service Level metadata from the Reporter to the Reporter - Service Level field. The result looks like this:
...
How-to use Metadata values within Scripted Fields - in Progress
Info |
---|
This how-to requires the installation of ScriptRunner for Jira |
Here we will show you how to use metadata values within a calculated custom field on an issue.
Within Jira, Scriptrunner field of type Text Field (multi-line) was created and named Financial expenditure. (Further details can be found here https://scriptrunner.adaptavist.com/latest/jira/scripted-fields.html and here https://scriptrunner.adaptavist.com/latest/jira/recipes/misc/table-custom-field.html )
For the example we use the metadata Hourly rate which is set in the project (further details about Project Screens can be found here: How to customize the Metadata Project Screen as Jira-Administrator). As shown here, it has the value 105.5.
...
In the Custom Script Field Financial expenditure the following Groovy script must be added under Script.
Code Block | ||
---|---|---|
| ||
import com.onresolve.scriptrunner.runner.customisers.WithPlugin
import com.onresolve.scriptrunner.runner.customisers.PluginModule
import com.osoboo.jira.metadata.MetadataService
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.customfields.manager.OptionsManager
import java.text.NumberFormat;
import java.util.Locale;
@WithPlugin("com.osoboo.jira-metadata-plugin")
@PluginModule
MetadataService metadataService
Long timeSpent = issue.timeSpent
NumberFormat currencyFormat = NumberFormat.getCurrencyInstance(Locale.US);
if (timeSpent > 0) {
Double hourlyRate = Double.parseDouble(metadataService.getMetadataValue(issue.getProjectObject(), "Hourly rate"))
return currencyFormat.format(timeSpent / 3600 * hourlyRate);
} else {
return currencyFormat.format(0.00);;
} |
For an issue on which 3 hours were logged, the following is now displayed:
...