Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Next challenges

Recent achievements

  • Global
  • Personal

Recognition

  • Give kudos
  • Received
  • Given

Leaderboard

  • Global

Trophy case

Kudos (beta program)

Kudos logo

You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.

View group

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Scriptrunner Listener Original Estimate Based On Custom Field Edited

Looking for some guidance as I'm stuck on my next steps...

My goal is to create a listener on a single project and when the "T-Shirt" custom field is set or modified (values are "S", "M", "L") we update the original estimate field with a corresponding value.

Small = 5d
Medium = 10d
Large = 15d

I've added a post function to test on new issue creation to set an original estimate, but still nothing is set (currently just testing the "M" size). 

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.issue.IssueEvent
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.security.JiraAuthenticationContext
import com.atlassian.jira.ComponentManager

def customFieldManager = ComponentAccessor.getCustomFieldManager()
def tshirt = customFieldManager.getCustomFieldObject(10142)
def tshirtsize = issue.getCustomFieldValue(tshirt)

if(tshirtsize =='M'){
MutableIssue issue=issue
issue.setEstimate ((long)288000)
IssueEvent event;
def currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
ComponentAccessor.getIssueManager().updateIssue(currentUser, issue, EventDispatchOption.ISSUE_UPDATED, false);
}
log.debug(tshirt);
log.debug(tshirtsize);

2019-12-10 00:18:42,530 DEBUG [workflow.ScriptWorkflowFunction]: T-Shirt
2019-12-10 00:18:42,530 DEBUG [workflow.ScriptWorkflowFunction]: M

Debug logs are showing the custom field and it's value correctly, so it's how I'm setting the original estimate field. Any help would be greatly appreciated.

1 answer

1 accepted

0 votes
Answer accepted

It is the "if" statement that is checking if the selection is M.

Select lists hold "options", not strings, so "if ( <option that is labelled as M> == 'M' )" is going to return a false.

I would usually do it this way:

if ( "M".equals(tshirtsize.getName() ) )

(I've had defensive coding kicked into me, and the use of .equals rather than == as it's safer for strings)

Thank you very much for your response @nic .

I tried to update the script with your suggestion and using import com.atlassian.jira.issue.fields per the API documentation (https://docs.atlassian.com/software/jira/docs/api/7.6.1/com/atlassian/jira/issue/fields/Field.html#getName--) but it's still cannot find the matching method for tshirtsize.getname().

Can you point me in the right direction? 

Suggest an answer

Log in or Sign up to answer
TAGS

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you