I'm currently trying to update a custom field during a transition that is triggered by a pull request merge. I tried doing this by accessing the info found on the "development" panel when JIRA and bitbucket are linked.
I tested this script on a scripted field type and was successful in getting the value I wanted
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.plugin.ComponentClassManager
import com.onresolve.scriptrunner.runner.customisers.WithPlugin
ApplicationUser currentUser = ComponentAccessor.jiraAuthenticationContext.getLoggedInUser()
IssueManager issueManager = ComponentAccessor.getIssueManager()
def ccm = ComponentAccessor.getComponentClassManager()
def devStatusSummaryService = ccm.newInstance("com.atlassian.jira.plugin.devstatus.impl.DefaultDevStatusSummaryService")
def issue = issueManager.getIssueObject(issue.getKey())
def pullRequestData = devStatusSummaryService.getDetailData(issue.id, "stash", "pullrequest", currentUser).right().get().getDetail()
def PRCollection = pullRequestData.pullRequests[0]
def i = 0
while (i < PRCollection.size()) {
def parsedRepoName = (PRCollection[i].destination.repository.name as String)?.replaceAll(/"/,'')
if (parsedRepoName[-1]== "C"){
if (PRCollection[i].status == "MERGED"){
return "U-RES"
}
}
i++
}
return "U-RES2"
however when I changed the script to set a custom field to that value during a transition as a post function it does not execute at all. I know that there aren't any sort of conditions blocking it because I have a separate unrelated custom scriptrunner post function on the same transition that does execute with no problem.(I see the number of successful runs go up while the other stays at "Has not run yet")
This is the script that doesn't execute
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.plugin.ComponentClassManager
import com.onresolve.scriptrunner.runner.customisers.WithPlugin
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.jira.issue.ModifiedValue
ApplicationUser currentUser = ComponentAccessor.jiraAuthenticationContext.getLoggedInUser()
IssueManager issueManager = ComponentAccessor.getIssueManager()
CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager()
def ccm = ComponentAccessor.getComponentClassManager()
def devStatusSummaryService = ccm.newInstance("com.atlassian.jira.plugin.devstatus.impl.DefaultDevStatusSummaryService")
def issue = issueManager.getIssueObject(issue.getKey())
def pullRequestData = devStatusSummaryService.getDetailData(issue.id, "stash", "pullrequest", currentUser).right().get().getDetail()
def PRCollection = pullRequestData.pullRequests[0]
def targetField = customFieldManager.getCustomFieldObjects(issue).find {it.name == "State"}
def changeHolder = new DefaultIssueChangeHolder();
def i = 0
while (i < PRCollection.size()) {
def parsedRepoName = (PRCollection[i].destination.repository.name as String)?.replaceAll(/"/,'')
if (parsedRepoName[-1]== "C"){
if (PRCollection[i].status == "MERGED"){
targetField.updateValue(null, issue, new ModifiedValue("U-RES"),changeHolder);
}
}
i++
}
targetField.updateValue(null, issue, new ModifiedValue("U-RES2"),changeHolder);
I tried researching the problem myself and saw that listeners could be the way to go but when I try using the same script in a listener I get a lot of errors regarding static type checking and stuff not existing. Any and all help would be appreciated