Update an issue via scriptrunner without editing fields

daniel_hedberg January 31, 2018

Hi,

 

Is it possible to just update an issue without modifying the data. The reason is that we are using Power Database Custom Fields and when the Custom Field data collected from the database is changed i would like to update the Jira Issues which has this customfield set to the new value.

 

 

2 answers

0 votes
Neta Elyakim
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.
February 1, 2018

You want to update issue or custom field(like add option from db to select list)?

daniel_hedberg February 1, 2018

Hi, 

The custom field in Jira is a Database Custom Field which collects the data of a value in a database of a person responsible for the customer. When the database value changes the field is not changed in Jira until i update issue and save.

 

What i guess happens is that when i edit an issue the database query which collects the value is run again.

 

The end result is that I would like this to happen on a schedule every night. But first i need to find a method which updates the issue and by updating the issue makes Jira run the database query again

Neta Elyakim
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.
February 1, 2018

Try this:

ApplicationUser user = userManager.getUserByName("UserName");
CustomField customField = customFieldManager.getCustomFieldObjectByName("customFieldName");
def CustomFieldValue = issue.getCustomFieldValue(customField);

IssueChangeHolder changeHolder = new DefaultIssueChangeHolder();
customField.updateValue(null, issue, new ModifiedValue(CustomFieldValue, user), changeHolder);

or this:

issue.setCustomFieldValue(CustomField,CustomFieldValuetoset);
issue.store()

Maybe try to reindex after the update:

import com.atlassian.jira.issue.index.IssueIndexingService
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.util.ImportUtils
import org.apache.log4j.Category

def issueManager = ComponentAccessor.getIssueManager()
def issueIndexingService = ComponentAccessor.getComponent(IssueIndexingService)

boolean wasIndexing = ImportUtils.isIndexIssues();
ImportUtils.setIndexIssues(true);
log.warn("Reindex issue ${issue.key} ${issue.id}")
issueIndexingService.reIndex(issueManager.getIssueObject(issue.id));
ImportUtils.setIndexIssues(wasIndexing);

 

 

0 votes
Ivan Tovbin
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.
February 1, 2018

Hi Erik,

Try this:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.UpdateIssueRequest

def currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
ComponentAccessor.getIssueManager().updateIssue(currentUser, issue, UpdateIssueRequest.builder().build())

daniel_hedberg February 1, 2018

Hi,

 

Thanks we have tried something similar but it seems the custom field does not update even though the PostFunction is applied.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events