Based on code example, located here i made behaviour with description template, but it not working right.
I guess, this part is not working
if (! underlyingIssue?.description) { desc.setFormValue(defaultValue) }Because underlyingIssue not exists while creating new issue. Am i right?
So i tried to do something like this:
//issuetype 10004 = bug
//get some values
def descriptionField = getFieldById("description")
def issueTypeField = getFieldById("issuetype")
def issueTypeValue = issueTypeField.getValue()
def descriptionValue = descriptionField.getValue()
def descriptionValue1 = descriptionField.getFormValue()
//define template
def templateValue = """h5. Env:
h5. Version:
h5. Bug description
h5. Steps to reproduce:
h5. Expected result:
h5. Actual result: """.replaceAll(/ /, '') + " " + descriptionValue + " " + descriptionValue1 //i've added description values here, to see, if it contain something
// if description already contain template, and issueType changed from bug to another, clear form
if (descriptionValue == templateValue && issueTypeValue != 10004){
descriptionField.setFormValue("")
}
//If descriptionValue not exist(if it null then?) and issuetype = bug, set description to template
if (!descriptionValue && issueTypeValue == 10004){
descriptionField.setFormValue(templateValue)
}
if (descriptionValue != templateValue && issueTypeValue == 10004){
return
}
I hope code not ruined, on creating this question, parser noticed, that some content was replaced.
Main thing that i want, is: when description equal template and type not equal bug, description field cleared. If description not exists and type equal bug, description filling with template. Third case is when description is not null, but not equal template -> do nothing
I got stuck in one thing, if description contain some information, descriptionValue still "Null".
If i add some logging, i get:
[c.o.j.groovy.user.FieldBehaviours] descriptionValue null
[c.o.j.groovy.user.FieldBehaviours] descriptionValue1 null
I found in some examples two possible(i think) methods of getting value of form, but all of them return Null. getValue works perfectly with all the fields, except description and summary. Maybe i'm doing something wrong.
So i have a question, how can i get current description on create issue screen, or i can only set it?
I need it not only to compare with template, but also to save content, for example if user started to create random issue, but later realise, that he's not setted issue type to bug, changing to bug, and all contents of description got cleared and filled with template, this is not a good thing.