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

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

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

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.

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);

 

 

Brilliant!  That worked perfectly.  Thank you smile

Suggest an answer

Log in or Sign up to answer
Community showcase
Posted Sep 25, 2018 in Jira

Atlassian Research Workshop opportunity on Sep. 28th in Austin, TX

We're looking for participants for a workshop at Atlassian! We need Jira admins who have interesting custom workflows, issue views, or boards. Think you have a story to sha...

465 views 7 5
Join discussion

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you