Hi Community,
I try to implement a workflow post-function with scriptrunner:
Given:
When:
Then:
The point is: the post-function/JQL doesn´t detect the issue that triggers it.
eg. let´s say I have "Issue B" already in status done and "Issue A" currently in status "In Planning" --> when "Issue A" gets transitioned to "Done" (which correctly fires the post function) the jql within the post-function still only detects "Issue B" (I would expect the JQL to return Issue A and Issue B).
My question is:
Isn´t that possible with post-function? Is the post-function firing faster than the transition is processed?
I even tried to shift down the post-function in the list:
Any help or hints appreciated.
Best
Stefan
> let´s say I have "Issue B" already in status done and "Issue A" currently in status "In Planning" --> when "Issue A" gets transitioned to "Done" (which correctly fires the post function) the jql within the post-function still only detects "Issue B" (I would expect the JQL to return Issue A and Issue B).
Ok, yes, there's a problem here - until the transition is complete (meaning everything has finished, including all the post-functions) Jira doesn't always have a definitive picture of the issue in its final shape. This is not because there's some special flag or something, it's because the issue is effectively cached until Jira knows that everything has worked. It doesn't actually get the final write to the database or even index, until the process has finished without error.
Two solutions to this are
thanks for your reply. I was thinking of indexing problems. It was just confusing for me as there is a seperate re-index post-function and I placed my scripted post-function after the re-index.
Furthermore I added following line to my script:
log.info("trigger-issue: " + issue.key + " status: "+issue.status.name)
which returns:
trigger-issue: SRT-15 status: Done
So still (as the script returns that my trigger issue is in status "Done") it doesn´t mean it´s REALLY indexed with status done? :D
Best
Stefan
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello Stefan,
Could you post your custom script maybe there is still a possibility in the script. In the simplest case a sleep of 20 seconds could be inserted.
Otherwise I would think of running the query via REST. I have the feeling REST is "faster" but also more programming effort.
Greeting,
Josef
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @DasJo ,
This is my script:
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.IssueManager;
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.bc.issue.search.SearchService
import com.atlassian.jira.issue.search.SearchException
import com.atlassian.jira.web.bean.PagerFilter
def issueService = ComponentAccessor.issueService
def customFieldManager = ComponentAccessor.customFieldManager
def issueManager = ComponentAccessor.issueManager
//getting customField objects for field budget and costs
def cfCourseCosts = customFieldManager.getCustomFieldObject("customfield_13400")
def cfBudget = customFieldManager.getCustomFieldObject("customfield_13303")
//get Issue (Budget Subtask) "Verbrauchtes Budget"
MutableIssue doneBudgetIssue = issueManager.getIssueByCurrentKey("BES-19")
def user = ComponentAccessor.jiraAuthenticationContext.loggedInUser
def searchService = ComponentAccessor.getComponentOfType(SearchService)
// The JQL query you want to search with
final jqlSearch = "project = BES and issuetype=Course and status = Done"
// Parse the query
def parseResult = searchService.parseQuery(user, jqlSearch)
if (!parseResult.valid) {
log.error('Invalid query')
return null
}
try {
// Perform the query to get the issues
def cumulativeDoneCourseCosts = (Double) 0
def results = searchService.search(user, parseResult.query, PagerFilter.unlimitedFilter)
def issues = results.results
log.warn("issues: "+issues)
// log.info("result: " + issues)
issues.each {
// log.info(it.key)
def costs = (Float) it.getCustomFieldValue(cfCourseCosts)
log.warn(costs)
cumulativeDoneCourseCosts = cumulativeDoneCourseCosts + costs
log.info("current cumulative: " + cumulativeDoneCourseCosts)
}
log.info("final calculation of course costs: " + cumulativeDoneCourseCosts)
// issues*.key
//set value of budget field to newly calculated/current budget
doneBudgetIssue.setCustomFieldValue(cfBudget, cumulativeDoneCourseCosts)
//update issue
issueManager.updateIssue(user, doneBudgetIssue, EventDispatchOption.DO_NOT_DISPATCH, false)
//log.info(costArray)
} catch (SearchException e) {
e.printStackTrace()
null
}
Regarding your input it seems to me that a wait will be more accurate as it seems it even works "too fast". An API call that is event faster would lead in the wrong direction i guess.
Best
Stefan
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @DasJo
tried a sleep in my script - that didn´t solve the problem. still the jql misses the issue that triggered the script.
eg:
there are 2 issues in status "Done":
Issue A
Issue B
Issue C is currently in status "In Planning" and is transitioned to "Done".
The workflow postfunction should now detect all issues in status "Done".
Nevertheless Issue C (which the post function was triggered by) is not detected.
Best
Stefan
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
A simple workaround could be that you take the field value of the current issue in addition to the JQL search. In scriptrunner you can read the triggering issue.
I'm not completely satisfied with the solution yet but it could be a first workaround.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
this could be a feasable workaround. Thanks for the hint ;)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @DasJo
I added your suggestion and (even if I´m not a fan of workarounds): It does exactly what it should.
Thanks for leading me into the right direction.
Best
Stefan
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
any hints from you? Isn´t it possible that the previously transitioned issue is detected by the jql?
--> when I transition Issue C to "Done" and a jql in post-function is searching for issues in status done currently Issue C is not detected by my jql. Isn´t the transition fully processed at the point of post function processing?
Best
Stefan
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.