Re-index customfield values in JIRA 4.4

Michal Danhel
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
August 4, 2013

Hello, i update custom field value in parent issue via Groove script (post-function in transition) in JIRA 4.4.3. After the value is updated, then i see in filter old value.

Can you tell me what i doing wrong? Thank you.

Here is my code:

import com.atlassian.jira.ComponentManager;
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.CustomFieldManager;
import com.atlassian.jira.issue.ModifiedValue;
import com.atlassian.jira.issue.fields.CustomField;
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder;
import com.atlassian.jira.issue.util.IssueChangeHolder;
import com.atlassian.jira.workflow.WorkflowTransitionUtil;
import com.atlassian.jira.workflow.WorkflowTransitionUtilImpl;
import com.atlassian.jira.util.ImportUtils;
import com.atlassian.jira.util.JiraUtils;
import com.opensymphony.workflow.WorkflowContext;

String stateFieldId = "customfield_13300";

CustomFieldManager cfm = ComponentAccessor.getCustomFieldManager();
WorkflowTransitionUtil workflowTransitionUtil = (WorkflowTransitionUtil)JiraUtils.loadComponent(WorkflowTransitionUtilImpl.class);
CustomField stateField = cfm.getCustomFieldObject(stateFieldId);

parent = issue.getParentObject();

Object oldValue = parent.getCustomFieldValue(stateField);
Object newValue = 2;

// Store the current state of indexing
Boolean wasIndexing = ImportUtils.isIndexIssues();

// Set indexing to true
ImportUtils.setIndexIssues(true);

// Do your changes on issue here!
stateField.updateValue(null, parent, new ModifiedValue(oldValue, newValue), new DefaultIssueChangeHolder());

// Reset Indexing
ImportUtils.setIndexIssues(wasIndexing);

2 answers

1 accepted

0 votes
Answer accepted
Michal Danhel
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
August 5, 2013

Thank you. For me works (JIRA 4.4.3):

IssueIndexManager indexManager = ComponentManager.getInstance().getIndexManager();

// Store the current state of indexing
Boolean wasIndexing = ImportUtils.isIndexIssues();

// Set indexing to true
ImportUtils.setIndexIssues(true);

// Do your changes on issue here!
stateField.updateValue(null, parent, new ModifiedValue(oldValue, newValue), new DefaultIssueChangeHolder());
indexManager.reIndex(issue);

// Reset Indexing
ImportUtils.setIndexIssues(wasIndexing);

0 votes
JamieA
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.
August 4, 2013

There is no call to

indexManager.reIndex(issue);

where indexManager is from: ComponentAccessor.getIssueIndexManager()

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events