Set custom field value based on condition

Hello,

We'd also like to see if we can create Rules around the reporter and stakeholder fields, i.e. if Reporter = a or b then Stakeholder = XYZ. This will save time in ticket creation and will also allow us to report out on tickets and progress more easily.

2 answers

This widget could not be displayed.
Gaston Valente Community Champion Dec 12, 2017

Laxmi,

this can be done by using a script post function or listner with script runner.

Do you need a code example?

Sure Gaston, Can you please send me an example on that.

This widget could not be displayed.
Gaston Valente Community Champion Dec 13, 2017

Here's a sample:


import com.atlassian.jira.event.issue.AbstractIssueEventListener;
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.security.JiraAuthenticationContext;
import com.atlassian.jira.user.ApplicationUser;
import com.atlassian.jira.issue.index.IssueIndexingService;
import com.atlassian.jira.bc.project.component.ProjectComponent;
import com.atlassian.jira.project.Project;
import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.issue.MutableIssue;
import com.atlassian.jira.issue.security.IssueSecurityLevelManager;
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.event.issue.IssueEventBundle
import com.atlassian.jira.event.issue.IssueEventManager
import com.atlassian.jira.event.issue.IssueEventBundleFactory
import com.atlassian.crowd.embedded.api.Group
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.IssueInputParameters;
import com.atlassian.jira.issue.IssueInputParametersImpl;
import com.atlassian.jira.bc.issue.IssueService;
import com.atlassian.jira.event.issue.IssueEvent
import com.atlassian.jira.event.issue.IssueEventDispatcher;
import com.atlassian.jira.util.ImportUtils;
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder;
import org.apache.log4j.Logger
import org.apache.log4j.Level

IssueService issueService = ComponentAccessor.getIssueService();
JiraAuthenticationContext authContext = ComponentAccessor.getJiraAuthenticationContext();

final IssueService.IssueResult issueResult = issueService.getIssue(authContext.getLoggedInUser(), issue.getKey());
final MutableIssue mutableIssue = issueResult.getIssue();

IssueInputParameters issueInputParameters = new IssueInputParametersImpl();
issueInputParameters.setSkipScreenCheck(true);
issueInputParameters.setRetainExistingValuesWhenParameterNotProvided(true, true);


issueInputParameters.setSecurityLevelId(12901L);
issueInputParameters.setAssigneeId("newassignee_username");
issueInputParameters.addCustomFieldValue("customfield_XXXXX","newvalue");


IssueService.UpdateValidationResult updateValidationResult = issueService.validateUpdate(
authContext.getLoggedInUser(),
mutableIssue.getId(),
issueInputParameters);

if (updateValidationResult.isValid())
{

IssueService.IssueResult updateResult = issueService.update(
authContext.getLoggedInUser(),
updateValidationResult,
EventDispatchOption.DO_NOT_DISPATCH,
false );

if (updateResult.isValid())
{
//OK
}
else{
//ERR
}
}
else
{
//Validation ERROR
}

Thanks for your quick replies Gaston. Where should i add the condition to change the stakeholder custom field automatically if Reporter = John or Eric then Stakeholder = Account Advisers. I am  very new to groovy scripts. I am not able to catch that.

Suggest an answer

Log in or Sign up to answer
Atlassian Summit 2018

Meet the community IRL

Atlassian Summit is an excellent opportunity for in-person support, training, and networking.

Learn more
Community showcase
Posted yesterday in New to Jira

Are you planning to trial, or are currently trialling Jira Software? - We want to talk to you!

Hello! I'm Rayen, a product manager at Atlassian. My team and I are working hard to improve the trial experience for Jira Software Cloud. We are interested in   talking to 20 people planning t...

49 views 1 0
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