ScriptRunner Behaviour doesn't work for create constrained issue

Frédérique Cusson June 22, 2020

Hello,

I have a problem with my Behaviour initialiser for the Constrained create issue Script Fragment. Even if I wrote all my code using if (getBehaviourContextId() == "link-create-LM") { , there is no change on my creating issue screen when i get to it using the button.

I read online that there were problems concerning Constrained create issue with behaviours, but I have Jira version 8.7.1 and ScriptRunner Version 6.2.1 so it should be okay. I also tried to place my button at different spots (operations-top-level and jira.issue.tools) and both don't work. 

The weirdest thing is that it was working at the beginning, but I changed a little bit my script and nothing works anymore. I tried to write the original screen back and nothing works.

Do anyone know what could be the problem ?

Here's my behaviour initialiser code

 

import com.atlassian.jira.component.ComponentAccessor
import com.onresolve.jira.groovy.user.FieldBehaviours

def issueManager = ComponentAccessor.getIssueManager()

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

def contextIssue = issueManager.getIssueObject(getContextIssueId())
def defaultValue = """PRJ créé à partir de : ${contextIssue.key}
En tant que
Je veux
Afin de """.replaceAll(/ /, '')

getFieldById("description").setFormValue(defaultValue)// Ajouter à la description et aux linked issues le lien vers l'Opportunité
getFieldById("issuelinks-linktype").setFormValue("relates to").setReadOnly(true)
getFieldById("issuelinks-issues").setFormValue(contextIssue.key).setReadOnly(true)
getFieldById("customfield_13800").setFormValue(contextIssue.getCustomFieldValue(customFieldManager.getCustomFieldObject("customfield_13800"))).setReadOnly(true)


def typeDemande = getFieldById("customfield_13800").getFormValue()
if (typeDemande == "Demande client") {
getFieldById("customfield_14012").setFormValue(contextIssue.getCustomFieldValue(customFieldManager.getCustomFieldObject("customfield_14012")))
getFieldById("customfield_10606").setFormValue(contextIssue.getCustomFieldValue(customFieldManager.getCustomFieldObject("customfield_10606")))
}
}

1 answer

1 accepted

0 votes
Answer accepted
Mathis Hellensberg
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.
June 22, 2020

Hi @Frédérique Cusson

I have tried setting this up in my instance and except for the customfields, which I don't have, it works perfectly.

Have you checked the logs for errors?

Frédérique Cusson June 23, 2020

 @Mathis Hellensberg Thanks for your answer. Because of what you said, I tried the script without the customfields and it is working. But when I add the customfields in the code nothing work. The project and Issue type fields aren't even Read only anymore. Do you have any idea what could be the problem?

Mathis Hellensberg
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.
June 23, 2020

Hmm maybe you got an ID wrong or one of the fields you are manipulating is of an unsupported type. Try adding one at a time to figure which one is failing :)

Like Responsable Infra likes this
Frédérique Cusson June 23, 2020

I found the problem, it is for all select list custom field. 

When i use getCustomFieldValue it returns a String, but setFormValue uses the option id of the custom field which is a long so it's not possible to set the form value that way. If anyone is interested by that issue, I set the form Value by using that script

def typeDemandeField = customFieldManager.getCustomFieldObject("customfield_13800")
def contextTypeDemande = contextIssue.getCustomFieldValue(typeDemandeField) as String
def config1 = typeDemandeField.getRelevantConfig(contextIssue)
def options1 = optionsManager.getOptions(config1)
def optionToSelect1 = options1.find { it.value == contextTypeDemande }
getFieldById("customfield_13800").setFormValue(optionToSelect1.optionId)
Mathis Hellensberg
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.
June 23, 2020

I’m glad you found a fix! :)

Suggest an answer

Log in or Sign up to answer