Set custom field value based on reporter

We have a custom field called Reason Code, enabled in Create Bug screen of our project. The requirement here is whenever there is a Bug created by a certain user X, we need to set the Status as OPEN and the Reason Code as Unverified.

 

Is there a simple script available for this? Any help would be greatly appreciated.

 

Thanks.

1 answer

Here is the script to check who performs an action and do a transition

import com.atlassian.jira.bc.issue.IssueService
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.IssueInputParameters
import com.atlassian.jira.user.ApplicationUser

//Get a user, who performs an action
ApplicationUser executor = ComponentAccessor.getJiraAuthenticationContext().getUser();
if(executor.getDisplayName().equals("user")){
    IssueService issueService = ComponentAccessor.getIssueService();
    IssueInputParameters inputParameters = issueService.newIssueInputParameters();
    IssueService.TransitionValidationResult transitionValidationResult = issueService.validateTransition(executor, issue.getId(), 1121, inputParameters);
    
    //Do the trnsotion
    if(transitionValidationResult.isValid()){
        issueService.transition(executor, transitionValidationResult);
    }
}

Let specify that it is not correct to say "set status". We can do some transition from current status to requared one. 

Since you should to add this script to a postfunction and then create a transition. On this transition you alse can add a postfunction to set requared value for field.

Suggest an answer

Log in or Sign up to answer
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Julia Dillon
Posted Tuesday in Jira

Tell us how your team runs on Jira!

Hey Atlassian Community! Today we are launching a bunch of customer stories about the amazing work teams, like Dropbox and Twilio, are doing with Jira. You can check out the stories here. The thi...

149 views 1 17
Join discussion

Atlassian User Groups

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

Find a group

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

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you