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

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

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

Suggest an answer

Log in or Sign up to answer
0 votes
Gaston Valente
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.
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.

0 votes
Gaston Valente
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.
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.

TAGS
AUG Leaders

Atlassian Community Events