Scriptrunner - need update customfield values faster

Cedacri
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!
May 10, 2024

Check out this snipper that updates a bunch of issues' customfields:

    for (issue in parentsIssue) {
       
        issue.update {
            setCustomFieldValue('xx', issue.getCustomFieldValue('yt').toDouble().round(1).toString())
            setCustomFieldValue('xc', issue.getCustomFieldValue('yy').toDouble().round(1).toString())
            setCustomFieldValue('xv', issue.getCustomFieldValue('yu').toDouble().round(1).toString())
            setCustomFieldValue('xb', issue.getCustomFieldValue('yi').toDouble().round(1).toString())

            setCustomFieldValue('xs', remaining_ce.round(1)?.toString())
            setCustomFieldValue('xd', remaining_ef.round(1)?.toString())
            setCustomFieldValue('xa', remaining_eg.round(1)?.toString())
            setCustomFieldValue('xy', remaining_xx.round(1)?.toString())
        }
    }
Neat right?
Thing is, for each issue with 8 customfields apiece, this takes too long, around 15~ seconds give or take per issue, and I need to iterate over potentially dozens of issues at once.
I've previously tried com.atlassian.jira.issue.fields.updateValue and it was somewhat faster, but not by much.
How can I do this faster?
My understanding that updateValue or setCustomFieldValue are calls to the DB that update the fields in question and it somehow loads it(?) Is it possible to edit the fields and 'commit' them all at once instead of a bunch of update calls?

2 answers

0 votes
Peter-Dave Sheehan
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
May 10, 2024

The "update" block should commit all the changes back to the database at once in a single transaction.

I would check that you don't have automations or other listeners that are then firing and delaying the execution of the subsequent loop.

0 votes
Matt Parks
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.
May 10, 2024

What causes the script to run? Is it part of a Behavior, a Script Listener? Automation rule?

When I'm updating issues like this, I typically do it in a Script Listener where I'll set the values and then run the following to update and re-index the issue. I've never had a problem with these updates taking a noticeable amount of time.

 

def issueIndexingService = ComponentAccessor.getComponent(IssueIndexingService);
def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
(do all of your custom field value setting in here)

ComponentAccessor.getIssueManager().updateIssue(user, issue, EventDispatchOption.DO_NOT_DISPATCH, false)
boolean wasIndexing = ImportUtils.isIndexIssues();
ImportUtils.setIndexIssues(true);
issueIndexingService.reIndex(ComponentAccessor.getIssueManager().getIssueObject(issue.id));
ImportUtils.setIndexIssues(wasIndexing);

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
SERVER
VERSION
9
TAGS
AUG Leaders

Atlassian Community Events