Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

ScriptRunner. Behaviour: issue links issue.

Serj Shcherbakov
Contributor
November 5, 2020

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

Suggest an answer

Log in or Sign up to answer
3 votes
Ravi Sagar _Sparxsys_
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Champions.
October 9, 2020

Hi @neeta jain 

You can can current date/time using this code.

Date dateObj = new Date()
def timestamp = new SimpleDateFormat('dd-MM-yyyy--HH-mm').format(dateObj)

Also please look for scripts on https://library.adaptavist.com/ you will find plenty of examples.

Ravi 

neeta jain
October 14, 2020

Hi Ravi,

After adding above 2 line code, its giving an error that simpledateformat is not available?

Can you please suggest the solution for it.

 

Regards,

Neeta Jain

Like Ravi Sagar _Sparxsys_ likes this
Ravi Sagar _Sparxsys_
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Champions.
October 14, 2020

Hi @neeta jain 

You need to add this line on top as well.

import java.text.SimpleDateFormat

Ravi

neeta jain
October 14, 2020

Thanks Ravi.

But when i return the value for timestamp, it just giving 14(today's date)

I wanted to apply formula for system date - end date.

So how would I get the exact date format, so that i can apply the formula.

 

Regards,

Neeta Jain

Ravi Sagar _Sparxsys_
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Champions.
October 14, 2020

You can modify the format if you want by modifying the argument

'dd-MM-yyyy--HH-mm'

Did you take a look at the example scripts on library? Take a look at this script to understand how to work with dates.

TAGS
AUG Leaders

Atlassian Community Events