JIRA custom field update & search not working properly

Within a JIRA listener plugin, from JIRA project A, after an issue update based of a trigger, I update an issue in JIRA project B.  Code as follows:

CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager();

CustomField customField = customFieldManager.getCustomFieldObject(10010);

IssueManager issueManager = ComponentManager.getInstance().getIssueManager();

MutableIssue currentMutableIssue = issueManager.getIssueObject(issue.getId());

currentMutableIssue.setCustomFieldValue(customField, valueToSave);

issueManager.updateIssue(currentMutableIssue.getReporterUser(), currentMutableIssue, EventDispatchOption.ISSUE_UPDATED, false);            

currentMutableIssue.store();

 

The value in the custom field of the issue in Project B is set correctly every time; however:

  • When the custom field is set to null (in ‘valueToSave’), then the field value is displayed on edit/view screen, and I can search it via JQL, etc.  I also notice the index is auto trigger too after update.
  • When the value is set to a non-null value, i.e. a number, the value is not displayed on the JIRA screen, and search not correct, until I manually update that issue in Project B!  Of course, I don’t see any auto index!

What am I missing here?  Thanks.

3 answers

0 votes
Aleksandr Zuevich Community Champion Oct 28, 2017

Hi!

Describe please the type of your custom field. What is Search Template set for this custom field?

Hi Aleksandr - This is a number field that comes with JIRA.  Search Template is Number Searcher.

0 votes
Aleksandr Zuevich Community Champion Oct 29, 2017

Try to update the issue using issueService instead of issueManager.

Actually it looks like there are some issue with the code logic causing this problem.  Everything seems to work now.  Thanks for the suggestion.

Actually it's not working again - look like one day it works, one day doesn't.  I have tried different approaches, but none work...   In fact I found similar issue on this site and I post my problem there - https://community.atlassian.com/t5/Answers-Developer-Questions/Update-an-issue-field-in-a-listener-changes-are-not-made/qaq-p/566449

Hi

I had the same problem like you. At the end I decided to reindex the issue manually when I change a customfield value. just add the following Codelines

final IssueIndexingService issueIndexingService =
(IssueIndexingService) ComponentAccessor.getComponent(IssueIndexingService.class);
issueIndexingService.reIndex(issue);

This should work just fine

Suggest an answer

Log in or Sign up to answer
Community showcase
Posted Sep 18, 2018 in Jira

What modern development practices are at the heart of how your team delivers software?

Hey Community mates! Claire here from the Software Product Marketing team. We all know software development changes rapidly, and it's often tough to keep up. But from our research, we've found the h...

24,932 views 2 7
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