Hi everyone,
I use behaviours because I want to change the description of my issues in accordance of the Pre-Qualification (it's a custom field which is a Select List).
But i don't know why but my script don't work except when I comment on the part between number 1 and 2. I don't see errors and when I put it in the "Script Console" the part(between number 1 and 2) works.
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.*
import com.atlassian.jira.issue.fields.*
//1
//Issue and CustomField Manager
IssueManager issueManager = ComponentAccessor.getIssueManager()
CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager()
//Issue's Id
long issueId = underlyingIssue.getId()
//the current issue
Issue issue = issueManager.getIssueObject(issueId)
//CustomField Name
CustomField customField = customFieldManager.getCustomFieldObjectByName("Pre-Qualification")
//Value of the CustomField of the current issue
Object customFieldValue = customField.getValue(issue)
//2
def desc = getFieldById("description")
def bugValue = """
*For a Bug
*Navigateur / Brower* : _Chrome v70, IE10 ..._
*Terminal / Device* : iPhone X iOS 12.0, Sony Xperia XZ1, Window XX, Mac, IPad, ..
*Environnement / Environment:* _QA , Prod, ..._
*Pré-requis / Pre-requisites* :
*Etapes / Steps* :
# _..._
# _..._
# _..._
*Résultat attendu / Expected result* : _Description_
*Résultat obtenu / Actual result* : _Description_
*Systématique / Systematic ?* _Y / N_
""".replaceAll(/ /, '')
if (!underlyingIssue?.created && !underlyingIssue?.description) {
if(customFieldValue.getValue() == "Bug"){
desc.setFormValue(bugValue)
}
}
to sum up, when i put this script without the part 1->2 in the behaviour edit its work but all the choice in the Pre-Qualification List have the same description which is "bugValue". And when i comment-out the part, nothing work and i don't know why.
i have tried this method:
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.*
def desc = getFieldById("description")
def bugValue = """
*For a Bug
*Navigateur / Brower* : _Chrome v70, IE10 ..._
*Terminal / Device* : iPhone X iOS 12.0, Sony Xperia XZ1, Window XX, Mac, IPad, ..
*Environnement / Environment:* _QA , Prod, ..._
*Pré-requis / Pre-requisites* :
*Etapes / Steps* :
# _..._
# _..._
# _..._
*Résultat attendu / Expected result* : _Description_
*Résultat obtenu / Actual result* : _Description_
*Systématique / Systematic ?* _Y / N_
""".replaceAll(/ /, '')
IssueManager issueManager = ComponentAccessor.getIssueManager()
CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager()
//long issueId = 92341
long issueId = underlyingIssue.getId()
Issue issue = underlyingIssue
//Issue issue = issueManager.getIssueObject(issueId)
def preQualification = customFieldManager.getCustomFieldObject("customfield_10203")
String preQualificationValue = preQualification.getValue(issue)
if(preQualificationValue=="Bug"){
desc.setFormValue(bugValue)
}
and this one:
import com.onresolve.jira.groovy.user.FieldBehaviours
import groovy.transform.BaseScript
@BaseScript FieldBehaviours fieldBehaviours
int preQualificationId = 10203
def preQualification = getFieldById("customfield_"+preQualificationId)
String preQualificationValue = preQualification.getValue()
def desc = getFieldById("description")
def bugValue = """
*For a Bug
*Navigateur / Brower* : _Chrome v70, IE10 ..._
*Terminal / Device* : iPhone X iOS 12.0, Sony Xperia XZ1, Window XX, Mac, IPad, ..
*Environnement / Environment:* _QA , Prod, ..._
*Pré-requis / Pre-requisites* :
*Etapes / Steps* :
# _..._
# _..._
# _..._
*Résultat attendu / Expected result* : _Description_
*Résultat obtenu / Actual result* : _Description_
*Systématique / Systematic ?* _Y / N_
""".replaceAll(/ /, '')
if(preQualificationValue == "Bug"){
desc.setFormValue(bugValue)
}
but nothing work, I don't understand why.
I think my issueId is not good.
Hi @baptistemuller ,
If you are willing to apply this behaviours when issue is being created right ? If so underlyingIssue object does not exist at this time yet, so I would not advise the first script.
What do the logs return if you use :
import com.onresolve.jira.groovy.user.FieldBehaviours
import groovy.transform.BaseScript
@BaseScript FieldBehaviours fieldBehaviours
int preQualificationId = 10203
def preQualification = getFieldById("customfield_"+preQualificationId)
String preQualificationValue = preQualification.getValue()
def desc = getFieldById("description")
def bugValue = """
*For a Bug
*Navigateur / Brower* : _Chrome v70, IE10 ..._
*Terminal / Device* : iPhone X iOS 12.0, Sony Xperia XZ1, Window XX, Mac, IPad, ..
*Environnement / Environment:* _QA , Prod, ..._
*Pré-requis / Pre-requisites* :
*Etapes / Steps* :
# _..._
# _..._
# _..._
*Résultat attendu / Expected result* : _Description_
*Résultat obtenu / Actual result* : _Description_
*Systématique / Systematic ?* _Y / N_
""".replaceAll(/ /, '')
log.error("preQualification field : " + preQualification)
log.error("preQualificationValue : " + preQualificationValue)
if(preQualificationValue == "Bug"){
log.error("setting the description...")
desc.setFormValue(bugValue)
}
Also, please provide a screenshot of your behaviours configuration.
Antoine
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
hello @Antoine Berry , ty for your asnswer, i've put your script in the script console:
error :
Cannot get property 'customfield_10203' on null object
log:
2019-05-02 14:32:01,321 WARN [common.UserScriptEndpoint]: Script console script failed: java.lang.NullPointerException: Cannot get property 'customfield_10203' on null object
at com.onresolve.jira.groovy.user.FormField.getValue(FormField.groovy:203)
at com.onresolve.jira.groovy.user.FormField$getValue$2.call(Unknown Source)
at Script100.run(Script100.groovy:8)
this is my behaviours configuration:
i hope it will help you.
Baptiste
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You should link the behaviours script to the Pre-Qualification field, not the Initializer, so it "listens" to any modification (therefore a it will detect when Bug is selected).
Are you sure 10203 is the id of the PreQualification field ?
Antoine
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
how i can link them ? with a server-side script ? with a condition ?
and yes i'm sure for the customfield id.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
i don't know if this can help you, but i have this log that i found in System/Audit Log:
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
So it seems to be working fine. The issue is that you are using the script in the Initializer. This means the script is called when you are displaying a screen for the first time.
In your case you need to map the script to the Pre-Qualification field, so that it is called each time you are changing this field value.
Just click on "Add server-side script" in the screenshot you have provided.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You are welcome ! Feel free to accept the answer if you are satisfied with it.
Also I would advise to add this condition
if (!underlyingIssue && desc.getValue() == "") {
if(preQualificationValue == "Bug"){
so that
But of course this is up to you and your needs !
Antoine
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @baptistemuller ,
Make sure to map the behaviour to the Pre Qualification custom field and kindly try this script (replace the custom field id) :
import com.onresolve.jira.groovy.user.FieldBehaviours
import groovy.transform.BaseScript
@BaseScript FieldBehaviours fieldBehaviours
int preQualificationId = 12900
def preQualification = getFieldById("customfield_" + preQualificationId)
def preQualificationValue = preQualification.getValue()
def desc = getFieldById("description")
if (!underlyingIssue && desc.getValue() == "") {
if(preQualificationValue == "Bug"){
def bugValue = """
*For a Bug
*Navigateur / Brower* : _Chrome v70, IE10 ..._
*Terminal / Device* : iPhone X iOS 12.0, Sony Xperia XZ1, Window XX, Mac, IPad, ..
*Environnement / Environment:* _QA , Prod, ..._
*Pré-requis / Pre-requisites* :
*Etapes / Steps* :
# _..._
# _..._
# _..._
*Résultat attendu / Expected result* : _Description_
*Résultat obtenu / Actual result* : _Description_
*Systématique / Systematic ?* _Y / N_
""".replaceAll(/ /, '')
desc.setFormValue(bugValue)
}
}
Antoine
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thank you again @Antoine Berry bu I don't understand why but this doesn't work, the console don't make any error but nothing change.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
The above script doesn't work ? There was a typo in the initial comment btw.
If I understood it right you want to set the description if "Bug" is selected ?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
yes that's right and if I select "Task" in the Pre-Qualification for example it will be another description.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Added some logs in the script, what do you get ?
import com.onresolve.jira.groovy.user.FieldBehaviours
import groovy.transform.BaseScript
@BaseScript FieldBehaviours fieldBehaviours
int preQualificationId = 12900
def preQualification = getFieldById("customfield_" + preQualificationId)
def preQualificationValue = preQualification.getValue()
log.error("preQualificationValue : " + preQualificationValue)
def desc = getFieldById("description")
log.error("desc.getValue() : " + desc.getValue())
log.error("underlyingIssue : " + underlyingIssue)
if (!underlyingIssue && desc.getValue() == "") {
if(preQualificationValue == "Bug"){
def bugValue = """
*For a Bug
*Navigateur / Brower* : _Chrome v70, IE10 ..._
*Terminal / Device* : iPhone X iOS 12.0, Sony Xperia XZ1, Window XX, Mac, IPad, ..
*Environnement / Environment:* _QA , Prod, ..._
*Pré-requis / Pre-requisites* :
*Etapes / Steps* :
# _..._
# _..._
# _..._
*Résultat attendu / Expected result* : _Description_
*Résultat obtenu / Actual result* : _Description_
*Systématique / Systematic ?* _Y / N_
""".replaceAll(/ /, '')
desc.setFormValue(bugValue)
}
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
2019-04-30 09:54:30,622 WARN [common.UserScriptEndpoint]: Script console script failed:
java.lang.NullPointerException: Cannot get property 'customfield_12900' on null object
at com.onresolve.jira.groovy.user.FormField.getValue(FormField.groovy:203) at com.onresolve.jira.groovy.user.FormField$getValue$2.call(Unknown Source) at Script667.run(Script667.groovy:8)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You need to replace 12900 with the id of your Pre-Qualification field
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
i think the double "if" condition don't allow the script to continu because when I comment it i can see the descrption in my issues
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.