Hi Team,
I am trying set checkbox value =yes, did I am missing anything in the following script. I am trying and doesn't setting as per the script.
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.customfields.manager.OptionsManager
import com.atlassian.jira.issue.fields.config.FieldConfig
def issue = event.issue as Issue
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def cf = customFieldManager.getCustomFieldObjectByName("Early Entry")//checkBox
def cf2 = customFieldManager.getCustomFieldObjectByName("EA Values")//text field
//check if cf2 not empty,then set Early Entry(checkbox) = Yes
if(cf2!=null){
def config = cf.getRelevantConfig(issue)
def options = ComponentAccessor.getOptionsManager().getOptions(config)
def optionsToSelect = options.findAll { it.value in ["Yes"] }
issue.setCustomFieldValue(cf, optionsToSelect)
}
Hello,
setCustomFieldValue is not enough. You need to use the following method after it
issueManager.updateIssue(userManager.getUser("user"), myIssue, EventDispatchOption.DO_NOT_DISPATCH, false)
You can find an example here
HI Alexey,
I have added following still doesnot work, I am missing any thing here.
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.customfields.manager.OptionsManager
import com.atlassian.jira.issue.fields.config.FieldConfig
import com.atlassian.jira.user.ApplicationUser;
import com.atlassian.jira.event.issue.IssueEvent;
import com.atlassian.jira.event.type.EventDispatchOption;
import com.atlassian.jira.event.type.EventTypeManager;
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def cf = customFieldManager.getCustomFieldObjectByName("Early Entry")//checkBox
def cf2 = customFieldManager.getCustomFieldObjectByName("EA Values")//text field
//check if cf2 not empty,then set Early Entry(checkbox) = Yes
if(cf2!=null){
Issue immutableIssue = event.getIssue();
IssueManager issueManager = ComponentAccessor.getIssueManager();
ApplicationUser user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser();
MutableIssue issue = issueManager.getIssueObject(immutableIssue.getKey());
def config = cf.getRelevantConfig(issue)
def options = ComponentAccessor.getOptionsManager().getOptions(config)
def optionsToSelect = options.findAll { it.value in ["Yes"] }
issue.setCustomFieldValue(cf, optionsToSelect)
issueManager.updateIssue(user, issue, EventDispatchOption.DO_NOT_DISPATCH, false);
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Are there any errors on the listener? Are you sure that issueManager.updateIssue was executed?
After issueManager.updateIssue try to reindex the issue. The code would be like this
boolean wasIndexing = ImportUtils.isIndexIssues(); ImportUtils.setIndexIssues(true); log.warn("Reindex issue ${issue.key} ${issue.id}") issueIndexingService.reIndex(issueManager.getIssueObject(issue.id)); ImportUtils.setIndexIssues(wasIndexing);
You can read more about reindexing here
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
By the way try to reindex the project where the issue was updated and have a look if the value appeared.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I have removed if logic for now to set the checkbox value.
throwing null pointer exception at ,Am i passing right argument.
java.lang.NullPointerException: Cannot invoke method getRelevantConfig() on null object
def config = cf.getRelevantConfig(issue)
Issue immutableIssue = event.getIssue();
def issueIndexingService = ComponentAccessor.getComponent(IssueIndexingService)
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def cf = customFieldManager.getCustomFieldObjectByName("Early Entry")//checkBox
def cf2 = customFieldManager.getCustomFieldObjectByName("EA Values")//text field
//check if cf2 not empty,then set Early Entry(checkbox) = Yes
IssueManager issueManager = ComponentAccessor.getIssueManager();
ApplicationUser user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser();
MutableIssue issue = issueManager.getIssueObject(immutableIssue.getKey());
def config = cf.getRelevantConfig(immutableIssue)
def options = ComponentAccessor.getOptionsManager().getOptions(config)
def optionsToSelect = options.findAll { it.value in ["Yes"] }
issue.setCustomFieldValue(cf, optionsToSelect)
issueManager.updateIssue(user, issue, EventDispatchOption.DO_NOT_DISPATCH, false);
boolean wasIndexing = ImportUtils.isIndexIssues();
ImportUtils.setIndexIssues(true);
log.warn("Reindex issue ${issue.key} ${issue.id}")
issueIndexingService.reIndex(issueManager.getIssueObject(issue.id));
ImportUtils.setIndexIssues(wasIndexing);
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
issue variable does not exist in your code. Do not use it in your code. You used it in serveral places. You defined only immutableIssue and you should use it. That is why it should be
def config = cf.getRelevantConfig(immutableIssue)
Fix all your code.
The error means that you pass null to the getRelevantConfig method.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
It means that event.getIssue(); returns null. Could you check it? Is it null? On what event your listener fires?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thank you I am able to set checkbox =yes,
But need to set based on if condition.
//check if 'eaIssueValue ' not empty,then set Early Entry(checkbox) = Yes
MutableIssue immutableIssue = issueManager.getIssueObject(issue.getKey());
def eaIssueValue = immutableIssue.getCustomFieldValue(eaIssues);
def eaIssueValue = issue.getCustomFieldValue(eaIssues);
if(eaIssueValue){
then set Early Entry(checkbox) = Yes
}
the if block is not executing the eaIssues is not empty.I am missing any thing here.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I can not see how you set eaIssues.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
def issue = event.issue as Issue
def issueIndexingService = ComponentAccessor.getComponent(IssueIndexingService)
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def earlyAc = customFieldManager.getCustomFieldObjectByName("Early Entry")//checkBox
def eaIssue = customFieldManager.getCustomFieldObjectByName("EA values")//text field
//check if cf2 not empty,then set Early Entry(checkbox) = Yes
IssueManager issueManager = ComponentAccessor.getIssueManager();
ApplicationUser user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser();
MutableIssue immutableIssue = issueManager.getIssueObject(issue.getKey());
def eaIssueValue = immutableIssue.getCustomFieldValue(eaIssue);
if(eaIssueValue){
def config = earlyAc.getRelevantConfig(immutableIssue)
def options = ComponentAccessor.getOptionsManager().getOptions(config)
def optionsToSelect = options.findAll { it.value in ["Yes"] }
immutableIssue.setCustomFieldValue(earlyAc, optionsToSelect)
issueManager.updateIssue(user, immutableIssue, EventDispatchOption.DO_NOT_DISPATCH, false);
boolean wasIndexing = ImportUtils.isIndexIssues();
ImportUtils.setIndexIssues(true);
log.warn("Reindex issue ${issue.key} ${issue.id}")
issueIndexingService.reIndex(issueManager.getIssueObject(issue.id));
ImportUtils.setIndexIssues(wasIndexing);
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Check the values of eaIssue, eaIssueValue with log.error. Do you have any errors in the log?
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.