Hey folks,
I'm spinning trying to get a scriptrunner script to work (either on Post Function or Automation). This script will process/fire when an "Automation for Jira" job picks an issue up and creates a linked issue. Essentially, the script consists of two parts:
Part 1:
From the new linked issue, get all issue links. Return with the Key of the issue links of a particular type. At this point it should only be 1 (the trigger issue) as it was just created. I have been working with something like this:
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.link.IssueLink
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.jira.issue.ModifiedValue
IssueManager im = ComponentAccessor.getIssueManager()
MutableIssue issue = im.getIssueObject("ADEMO-11") //TODO: Get current issue instead of static issue
// For later, to get the issue its on: def issue = ComponentAccessor.issueManager.getIssueByCurrentKey(issueKey)
def issueService = ComponentAccessor.issueService
def loggedInUser = ComponentAccessor.jiraAuthenticationContext.loggedInUser
def links = ComponentAccessor.getIssueLinkManager().getOutwardLinks(issue.getId())
def keys = ""
for( l in links) {
keys = keys + l.getDestinationObject()
}
return keys
This is great, and in the future I will be updating issue to point to the current issue.
Part 2:
A switch or if statement to compare the linked issue keys with Regex. For the sake of testing right now, I'm just using a text field:
if(issue){
//get the value
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def cField = customFieldManager.getCustomFieldObject("customfield_18701")
def cFieldValue = issue.getCustomFieldValue(cField)
//update the value
def changeHolder = new DefaultIssueChangeHolder()
cField.updateValue(null, issue, new ModifiedValue(cFieldValue, "Testing if this works!"),changeHolder)
//TODO: Configure to use Cascading select list
}else {
return "Nothing is linked"
}With this part, i'm able to pass a string. However, I really want to be passing what I'm returning as `keys` in part 1. I feel like I'm missing something very obvious.
My questions:
- How do I get the linked issue 'keys' to populate in that field? I can get them to print in logs and console, but when I try to send them as NOT a string it silently fails.
- Ultimately I want to be setting the value of a cascading select list based off of the project key. I'm confident with doing the regex or compare statement, but I'm not finding any documentation for setting a cascading select. Can someone point me in the right direction, or share an example? I'm only finding ways to do this over REST.