Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
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

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

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

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.

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

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
TAGS
Community showcase
Published in Jira Software

👋 Looking for 15-20 volunteers to test Atlassian training content

Hi everyone! Are you interested in beta testing Atlassian University’s newest (unreleased!) training course? We’re looking for 15-20 volunteers to test our newest training course, Basic reporting...

782 views 24 28
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