Script Runner behavior does not work for Create Constrained Issue script fragment

SWAPNIL SRIVASTAV January 3, 2022

Script Runner behavior does not work for Create Constrained Issue script fragment when we right click on the button and perform "Open in a new tab". I made some fields readOnly and hidden using behaviour script. The create screen is displayed and the fields are not readOnly.

When we left click and create screen appears as a prompt window, then everything works fine. I found this bug where it is shown as fixed for version 5.5.5 and above and I am using script runner version-6.35.0 and jira version- 8.13.3.

 

Could anyone please help

3 answers

0 votes
SWAPNIL SRIVASTAV January 4, 2022

Hello @Ram Kumar Aravindakshan _Adaptavist_ , @Muhammad Fahad ,

Yes, I connected with script runner support and they confirmed that this is a known bug and they provided a workaround:

By adding a query contextIssueId=${issue.id} into the link when open with right click. To do that, you press the Preview button generates the XML for the Create Constrained Issue fragment, which you can then modify and submit via raw xml module.

After that you can capture the query in Behaviour using following snippet:

def contextIssueId = getContextIssueId()
if (!contextIssueId) {
    def referer = getRequest().getHeader("referer")
    def url = new URL(referer)
    def queryParams = url.query?.split('&')
    def mapParams = queryParams.collectEntries { param -> param.split('=').collect { URLDecoder.decode(it) } }
    contextIssueId = mapParams["contextIssueId"]
}
log.warn "contextIssueId is: " + contextIssueId

 

Accordingly, I have made modifications. Added the Raw XML Module and below is the updated behaviour initializer script mapped to target project and target issue type:

 

 

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.label.LabelManager
import com.atlassian.jira.issue.Issue

def customFieldManager = ComponentAccessor.getCustomFieldManager()
def issueManager = ComponentAccessor.getIssueManager()
def contextIssueId = getContextIssueId()
log.error "contextIssueId--"+contextIssueId
if (!contextIssueId) {
log.error "no context Issue"
def referer = getRequest().getHeader("referer")
def url = new URL(referer)
def queryParams = url.query?.split('&')
def mapParams = queryParams.collectEntries { param -> param.split('=').collect { URLDecoder.decode(it) } }
contextIssueId = mapParams["contextIssueId"]
log.error "contextIssueId----"+contextIssueId
}
//def contextIssue = contextIssueId as Issue
def contextIssue = issueManager.getIssueObject(contextIssueId)
log.error "contextIssue after converting to issue object-- "+contextIssue
LabelManager labelManager = ComponentAccessor.getComponent(LabelManager)
def contextIssueWorkingCommentCF = customFieldManager.getCustomFieldObjectsByName("Working Comment").first()
def contextIssueNoCF = customFieldManager.getCustomFieldObjectsByName("No.").first()

if (getBehaviourContextId() == "P3_buttonToCreateBUS") {
log.error "in behaviour context"
getFieldById("project-field").setReadOnly(true)
getFieldById("issuetype-field").setReadOnly(true)
getFieldById("summary").setFormValue("${contextIssue.summary}")
getFieldById("issuelinks-linktype").setFormValue("was moved to").setHidden(true)
getFieldById("issuelinks-issues").setFormValue(contextIssue.key).setHidden(true)

if(contextIssue.getDescription())
getFieldById("description").setFormValue("${contextIssue.description}")
if (contextIssue.getPriority()) {
def prioValue = contextIssue.getPriority().getName() as String
getFieldById("priority").setFormValue(prioValue)
}
if (contextIssue.getCustomFieldValue(contextIssueWorkingCommentCF)) {
def contextIssueWorkingCommentValue = contextIssue.getCustomFieldValue(contextIssueWorkingCommentCF) as String
getFieldByName("Working Comment").setFormValue(contextIssueWorkingCommentValue)
}
if (contextIssue.getCustomFieldValue(contextIssueNoCF)) {
def contextIssueNoValue = contextIssue.getCustomFieldValue(contextIssueNoCF) as Double
getFieldByName("No.").setFormValue(contextIssueNoValue)
}
def labels = labelManager.getLabels(contextIssue.id)
def values = []
labels.each { values.add(it.getLabel()) }
def labelField = getFieldById("labels")
if (!labels.isEmpty())
labelField.setFormValue(values)
}
else {
getFieldById("issuelinks-linktype").setHidden(true)
getFieldById("issuelinks-issues").setHidden(true)
}

 

 But it is not working because the contextIssue is returned as null

Could you please guide.

0 votes
Ram Kumar Aravindakshan _Adaptavist_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
January 3, 2022

Hi @SWAPNIL SRIVASTAV

Could you please share the Behaviour code that you are using along with a print screen of your Behaviour configuration?

Also, please try to upgrade your ScriptRunner plugin to the latest version released, i.e. 6.41.0, and try to retest it once again.

Thank you and Kind Regards,
Ram

0 votes
Muhammad Fahad
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 Leaders.
January 3, 2022

Hi @SWAPNIL SRIVASTAV - This can be a regression issue un 6.35.0. You may reach out to https://docs.adaptavist.com/sr4js/latest/get-help for product detailed help.

Suggest an answer

Log in or Sign up to answer