Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Deleted user
0 / 0 points
Next:
badges earned

Your Points Tracker
Challenges
Leaderboard
  • Global
  • Feed

Badge for your thoughts?

You're enrolled in our new beta rewards program. Join our group to get the inside scoop and share your feedback.

Join group
Recognition
Give the gift of kudos
You have 0 kudos available to give
Who do you want to recognize?
Why do you want to recognize them?
Kudos
Great job appreciating your peers!
Check back soon to give more kudos.

Past Kudos Given
No kudos given
You haven't given any kudos yet. Share the love above and you'll see it here.

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

script listener update checkbox =yes?

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)
}

 

1 answer

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

https://community.atlassian.com/t5/Marketplace-Apps-questions/Scriptrunner-Update-summary-field-from-a-custom-listener/qaq-p/461017

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);

}

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

https://community.atlassian.com/t5/Answers-Developer-Questions/Issue-reindex-from-groovy-script/qaq-p/509901 

By the way try to reindex the project where the issue was updated and have a look if the value appeared.

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);

 

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.

Sorry , I have coded 
def config = cf.getRelevantConfig(issue) only, but same null point error

It means that event.getIssue(); returns null. Could you check it? Is it null? On what event your listener fires?

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.

I can not see how you set eaIssues. 

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);
}

Check the values of eaIssue, eaIssueValue with log.error. Do you have any errors in the log?

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase

The benefits of using Jira in different departments

Jira is a great tool to use across different departments. Forget that paperwork – switch to Jira and get that tasks done smoothly. Marketing Jira allows for a complete digital transformation of you...

75 views 0 4
Read article

Community Events

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

Find an event

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

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you