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

Unable to unflag an issue using Script Runner groovy code

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

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

Thanks @Tuncay Senturk _Snapbytes_  your suggestion solved my problem.

I'm glad that it worked ;) 

Suggest an answer

Log in or Sign up to answer
TAGS

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