Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Next challenges

Recent achievements

  • Global
  • Personal

Recognition

  • Give kudos
  • Received
  • Given

Leaderboard

  • Global

Trophy case

Kudos (beta program)

Kudos logo

You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.

View group

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

ScriptRunner. Behaviour: issue links issue.

Hi there,

I am trying to change the type of link on the screen depending on the context key of the task.

for example, when calling the screen from a task with any issuekey excepting than "CPWEB-75", add a link type "Linked to Testing".

Also if the issuekey is "CPWEB-75", then put the link type "is blocked by"

To rich it is i using scriptrunner modulles script fragment's and behaviour's.

Inside of behaviour settings i putted my script into Initialiser field. 

When i testing sript it always return only one link type "Linked to Testing". Could you help with it?

My Script:


import com.onresolve.jira.groovy.user.FieldBehaviours
import static com.atlassian.jira.issue.IssueFieldConstants.*
import groovy.transform.BaseScript
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.user.ApplicationUser

def issueManager = ComponentAccessor.getIssueManager()
def contextIssue = issueManager.getIssueObject(getContextIssueId())
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def versionManager = ComponentAccessor.getVersionManager()
def issuelinks = getFieldById("issuelinks-linktype")

if (getBehaviourContextId() == "link-create-blocking") {
getFieldById("project-field").setReadOnly(true)
getFieldById("issuetype-field").setReadOnly(true)


if (contextIssue != "CPWEB-75") {

log.warn "contextIssue : ${contextIssue}"

issuelinks.setFormValue("Linked to Testing").setReadOnly(false)
log.warn "issuelinks : ${issuelinks}"

getFieldById("issuelinks-issues").setFormValue(contextIssue.key).setReadOnly(false)
getFieldById("versions").setFormValue(contextIssue.fixVersions*.id)

def epicLinkCf = customFieldManager.getCustomFieldObjectByName("Epic Link")
def linkedEpic = contextIssue.getCustomFieldValue(epicLinkCf) as Issue
if (linkedEpic) {
getFieldByName("Epic Link").setFormValue(linkedEpic.key).setReadOnly(true)
}
} else {
if (contextIssue == "CPWEB-75") {

log.warn "contextIssue : ${contextIssue}"

issuelinks.setFormValue("is blocked by").setReadOnly(false)
log.warn "issuelinks : ${issuelinks}"

getFieldById("issuelinks-issues").setFormValue(contextIssue.key).setReadOnly(true)
getFieldById("versions").setFormValue(contextIssue.fixVersions*.id)
}
}
}

 

1 answer

0 votes

Hi there, 

You may find that using the "underlyingIssue" variable – which is automatically available to you in ScriptRunner's Behaviour context – is a more simple way to perform this sort of conditional logic.

I'm not sure which version of ScriptRunner that you are using, but in more recent versions of ScriptRunner the "Linked Issues" field and its associated "Issue" form value can be accessed using the following IDs:

  • Linked Issues: getFieldById("issuelinks-linktype") 
  • Issue: getFieldById("issuelinks-issues-textarea")

Screenshot 2020-11-30 at 13.39.47.png

So, when you combine the "underlyingIssue" variable with the correct field IDs, you can modify the linked issues using a more simple script, as I've shown below: 

// Linked Issues Field
def issueLinks = getFieldById("issuelinks-linktype")
log.warn "Linked Issues Field: ${issueLinks.value}"

// Linked Issue
def linkedIssue = getFieldById("issuelinks-issues-textarea")
log.warn "Linked Issue: ${linkedIssue}"

if (underlyingIssue.key != "KEY-123") {
issueLinks.setFormValue("your-value")
linkedIssue.setFormValue(underlyingIssue.key)
} else if (underlyingIssue.key == "KEY-123") {
// do something else
}  

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Opsgenie

Investigate deployment-related incidents with Bamboo and Opsgenie together

Back in April of last year one of the major product announcements from Opsgenie was the launch of the Incident investigation view which created a deep connection between Bitbucket and Opsgenie, empow...

94 views 1 4
Read article

Community Events

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

Find an event

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

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you