What is the difference between an inline script and one on the server?

Jodi Gornick July 5, 2016

I am using scriptrunner and I was trying to use the Script Listener to trigger on the issue close event to set remaining estimate to zero.  When I create this and enter the script through the inline entry it does not work.  When I create on the server (exact same script) and call the script file instead it works.  

I would prefer to have my developers work through the inline script method instead of given server access.

What is the difference between this two methods?

Thank you!

 

1 answer

1 vote
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.
July 6, 2016

In this context, there should be no difference. "Not works" - how? Checked the logs?

Jodi Gornick July 6, 2016

The Inline script option when showing successful executions, states it was successful. However remaining estimate is not set to 0. I have no error messages in the log files.

Note the following script will produce compile errors. I have an inline version that does not produce errors, but that did not solve any problems.

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.issue.AbstractIssueEventListener
import com.atlassian.jira.event.issue.IssueEvent
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.index.IssueIndexManager
import com.atlassian.jira.util.ImportUtils

class RemainingEstimateZero extends AbstractIssueEventListener {
@Override
void workflowEvent(IssueEvent event) {
def componentAccessor = new ComponentAccessor()
IssueIndexManager indexManager = ComponentAccessor.getComponent(IssueIndexManager.class)
def MutableIssue issue = event.getIssue()

//used to reindex the issue at the bottom
boolean wasIndexing = ImportUtils.isIndexIssues();
ImportUtils.setIndexIssues(true);

if (issue.estimate == null || issue.estimate > 0)
issue.setEstimate(0)

//reindex issue
indexManager.reIndex(issue);
ImportUtils.setIndexIssues(wasIndexing);
}
}

Taking this same script and placing it in the jira/scripts folder and pointing the listener to (with same compile errors) works successfully.  On transition to close the remaining estimate is set to 0.

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.
July 7, 2016

oh ok - for event listeners IIRC you need to structure that as a script to use it inline, not a class.

So, you should end up with (after cleanup):

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.index.IssueIndexManager
import com.atlassian.jira.util.ImportUtils

IssueIndexManager indexManager = ComponentAccessor.getComponent(IssueIndexManager.class)
def MutableIssue issue = event.getIssue()

//used to reindex the issue at the bottom
boolean wasIndexing = ImportUtils.isIndexIssues();
ImportUtils.setIndexIssues(true);
if (issue.estimate == null || issue.estimate > 0)
    issue.setEstimate(0)
//reindex issue
indexManager.reIndex(issue);
ImportUtils.setIndexIssues(wasIndexing);

 

 

Jodi Gornick July 7, 2016

Brilliant!  That worked perfectly.  Thank you smile

Suggest an answer

Log in or Sign up to answer