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.
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?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.