Jira field calculated based on another field.

KPAH
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 10, 2013

I have several Jira issues with assignees. I need a custom field called "Entity", which will set VALUE1 if asigenee equalts name1, name2 and name3, and set VALUE2 if assignee equals name4, name5 and name6. If assignee changes from belonging to VALUE1 to VALUE2, this field should reflect that.

How can I achieve that? thanks

3 answers

1 accepted

3 votes
Answer accepted
John Bishop
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 11, 2013

The Script Runner plugin would work well for this.

https://marketplace.atlassian.com/plugins/com.onresolve.jira.groovy.groovyrunner

After installing this plugin you can create a Scripted Field. In this scripted field you would create a groovy script which would dynamically set its value based on the assignee.

Your script might look something like this:

if (issue.getAssignee().getDirectoryId() == "name1" ||
issue.getAssignee().getDirectoryId() == "name2" ||
issue.getAssignee().getDirectoryId() == "name3")
{
	return "VALUE1";
}
else if (issue.getAssignee().getDirectoryId() == "name4" ||
issue.getAssignee().getDirectoryId() == "name5" ||
issue.getAssignee().getDirectoryId() == "name6")
{
	return "VALUE2";
}

KPAH
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 11, 2013

This one can send emails on transitions, which I am to use for another project :) Thanks

JamieA
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 11, 2013

I don't think you want getDirectoryId(), but the principle is correct.

KPAH
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 11, 2013

yeah, I figured out

issue.getAssignee().getDisplayName() == "Last, First"

works like a charm.

Thanks again, your input was most helpful. It only took me like 2 hours to figure out you have to set searcher=none for the scripted field to display :)

JamieA
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 11, 2013

And you should use:

issue.getAssignee()?.getDisplayName()

because it can be possible to have issues without a reporter - see https://jamieechlin.atlassian.net/wiki/display/GRV/Built-In+Scripts#Built-InScripts-Safenavigation.

JamieA
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 11, 2013

I'll get to your review comment on the plugin... however this is not correct. Only set the searcher to none if you don't want to search on the issue. The reasons for it not displaying are:

* Not associated with the project / issue type
* Not on the view screen
* Scripted field not configured, or not configured properly, ie no script or no template, or errors in script (all these in the third bullet can be checked with the preview facility).

KPAH
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 11, 2013

This works in search, but obviously doesn't appear in gadgets as filter selection. Can I somehow make a "solid" custom field, and then amend this script to be run say once in an hour, so it will populate the field with the needed value?

John Bishop
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 11, 2013

You could add a group picker field to the screen and then use the scripted field to just update the value of the group picker field. If you don't have the scripted field's script return a value, the scripted field will remain hidden.

The scripted field will then update the group picker field every time someone views that issue.

JamieA
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 11, 2013

To make it appear for filter selection you should install https://marketplace.atlassian.com/plugins/sk.eea.jira.natural-searchers, and use the supplied indexer as the calculated field indexer.

KPAH
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 11, 2013

Thank you so very much for your work and kind responsiveness! Auto-add watchers! Auto-create tasks on transitions! Maybe now I'll finally make them assignees to complete required paperwork for each status.:)

PS: Just interested - what operator will set a custom field value from script (or pick the group)? I'm browsing the wiki now but can't see to find it.

If I hide the scripted field in the Fields Sheme, will it still be operational to set another field?

John Bishop
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 12, 2013

I use the updateValue method.

http://docs.atlassian.com/jira/latest/com/atlassian/jira/issue/fields/CustomFieldImpl.html

For example, I have a script which sets the subtask summary to match the parent issue, so I use the command:

Summary.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(Summary), parent.getCustomFieldValue(Summary)), new DefaultIssueChangeHolder());

For a group picker field, you will probably have to change the values you pass to the ModifiedValue function.

As far as hiding the scripted field, I'm not sure what effect that will have.

JamieA
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 12, 2013

You can hide it, it won't cause any problems.

0 votes
Lauren Robinette March 1, 2019

Hi @John Bishop , @Radu Dumitriu, I'm trying to use this same logic, but for setting date fields. I'm already using this code to set the date field, based on a single selection (Physical Addresses). But there are two other selections, where I'd like the number of days that populate to be 10 business days. Any thoughts on how to implement that?

I understand that I would need to remove the Conditional Execution and put that into the Groovy Scripting.

physical addresses.JPG

 

cc: @Jordan Lem 

0 votes
Radu Dumitriu
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 11, 2013
KPAH
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 11, 2013

This seems to be the simpliest solution, thanks.

KPAH
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 11, 2013

Sorry, SIL costs money, that's against my company policy to spend any more money on Atlassian

Radu Dumitriu
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 11, 2013

Nope, it's free.

KPAH
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 11, 2013

Ok maybe I was not correct.

Balakrishna M June 26, 2018

This is available only for Jira server not for jira clound, can anyone help me with the same problem in Jira cloud

Carol Jones February 12, 2019

Looks like overtime, this free app has gone paid.  😕

Like # people like this

Suggest an answer

Log in or Sign up to answer