Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Unable to unflag an issue using Script Runner groovy code

Hitendra Chauhan
Contributor
January 9, 2020

I have a problem in unflagging an issue using script runner groovy code.

It seems that somehow re-index is not happening.

Can anyone help ?

def customFieldManager = ComponentAccessor.getCustomFieldManager();
def customFields = customFieldManager.getCustomFieldObjects();
IssueManager im = ComponentAccessor.getIssueManager();
def flaggedCF = customFields.findByName("Flagged");
MutableIssue flaggedIssue = im.getIssueObject("TEST-1");
flaggedIssue.setCustomFieldValue(flaggedCF, null);

boolean isIndex = ImportUtils.isIndexIssues();
ImportUtils.setIndexIssues(true);
IssueIndexingService IssueIndexingService = (IssueIndexingService) ComponentAccessor.getComponent(IssueIndexingService.class);
IssueIndexingService.reIndex(flaggedIssue);
ImportUtils.setIndexIssues(isIndex);

 

1 answer

1 accepted

0 votes
Answer accepted
Tuncay Senturk
Community Champion
January 9, 2020

Hi @Hitendra Chauhan 

Instead of 

flaggedIssue.setCustomFieldValue(flaggedCF, null);

try this one

IssueChangeHolder changeHolder = new DefaultIssueChangeHolder();
flaggedCF.updateValue(null, flaggedIssue, new ModifiedValue(flaggedIssue.getCustomFieldValue(flaggedCF), null), changeHolder)

Tuncay

Hitendra Chauhan
Contributor
January 9, 2020

Thanks @Tuncay Senturk  your suggestion solved my problem.

Tuncay Senturk
Community Champion
January 10, 2020

I'm glad that it worked ;) 

Suggest an answer

Log in or Sign up to answer