Hello all. I've checked a lot of posts, but in most cases it was 2013-2014 years and I wish there could be experienced people with 2017 best bractices.
So, I have pretty complicated case which I'll try to cut for 2 parts:
1) if a bug field 'Environment'(Select list, single choice) has a selection 'Production', field 'SD'(Number field) should appears and this field should be required. When 'SD' field got a number, and when a bug goes to one of 3 statuses 'One', 'Two', 'Three', there should appears two more custom fields named 'Fix'(text field) and 'TestCase'(text field) which should be required both, and also two more custom fields 'Version' and 'QF" which are not required both.
2) when a bug reach one of those 3('One' ,'Two', 'Three') statuses, there should start an e-mail notifications for futher statuses until this bug will be closed. E-mail notifications should has a Subject with a number from 'SD' field(like, ##12345##), and also inside of a body of e-mail has the infortmation from few custom fields like 'Fix', 'TestCase', 'Version', 'QF'(example, Fix: yes we will fix it somehow; Version: 11; etc).
I'll be very glad if someone has any advices how this case can be configured in a best way and I'll be very thankful for any help.
Thanks in advance!
Both these scenarios can be achived using Script runner JIRA plugin.
1) For first case use Behaviour plugin, wherein you can modify one custom field based on the value of another.
Following things can be done
The behaviours functionality allows an administrator to create one more or behaviours. A behaviour defines how fields behave for issues in a given project or issue context. Some examples of behaviours are:
Making a field mandatory depending on other data entered on the issue screen (i.e during an issue creation or an issue transition)
Making a field read-only dependent on user role or group
Doing server-side validation of field data, before the issue screen is submitted
Setting a field value dependent on other issue screen data
Full docs here -
https://scriptrunner.adaptavist.com/latest/jira/behaviours-overview.html
You can also use Javascript to make a custom field mandatory based on value of other
The above steps use client side validation. But if you want some validation to perform after the user has *clicked* on create button then you need to put the logic in the "validation" phase of the create transition of the workflow and that configuration will be part of the workflow configuration in the backend.
2) For the second scenario , you can use the "send custom email" postfunction of the script runner plugin to send cutomized email for every workflow status
https://scriptrunner.adaptavist.com/4.3.1/jira/builtin-scripts.html#_send_a_custom_email
Hello Tarun and thank you for your answer!
So, I'm in the middle of point 1, but faced with a little problem -
I've tried to edit the script from example of behaviour, like this:
import com.atlassian.jira.issue.fields.CustomField
def CustomField = getFieldById("customfield_10009")
def Custom2Field = getFieldById("customfield_11503")
def custom = CustomField.getValue() as Custom
if (Custom.name == "Production") {
Custom2Field.setRequired(true)
Custom2Field.setHidden(false)
}
else {
Custom2Field.setRequired(false)
Custom2Field.setHidden(true)
}
But I got an error like: Compilation failure: startup failed: Script1.groovy: 8: unable to resolve class Custom @ line 8, column 37. def custom = CustomField.getValue() as Custom ^ 1 error
I understand, that the problem with
def custom = CustomField.getValue() as Custom
But I can't find what class I should write there instead of Custom?
And one thing more - about Javascript for make a field mandaroty etc, I've tried it before I posted a case here, but I've also faced with similar problem - edit script exactly for a custom field and it didn't work at the end. So, anyway, it's not so important right now, and I'm better to know which class I should to fill in a behaviour part.
Thank you!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I couldn't find a class called "Custom" in the APi that explains the error, can you try like the code given in this sample-
https://idalko.com/use-behaviour-functionality-script-runner-show-hide-fields/
i.e. directly check for value form the customfield instead of using "as" andif it still complains try putting a cast to an String.
if (dropDown.getValue() == "a") {
conditionA.setHidden(false);
conditionB.setHidden(true);
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.
Good to hear that you have finished the first part successully, let me know if you face any issues in the 2nd part.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Tarun, thank you very much for help!
It's my code below, maybe it will help someone.
Behaviour fields:
import com.atlassian.jira.issue.fields.CustomField
def CustomField = getFieldById("customfield_10009")
def Custom2Field = getFieldById("customfield_11507")
def Custom3Field = getFieldById("customfield_11504")
def Custom4Field = getFieldById("customfield_11505")
if (CustomField.getValue() == "Production") {
Custom2Field.setRequired(true)
Custom2Field.setHidden(false)
Custom3Field.setRequired(false)
Custom3Field.setHidden(false)
Custom4Field.setRequired(false)
Custom4Field.setHidden(false)
}
else {
Custom2Field.setRequired(false)
Custom2Field.setHidden(true)
}
import com.atlassian.jira.issue.fields.CustomField
def Custom3Field = getFieldById("customfield_11504")
if (getActionName() == "TEST" || getDestinationStepName() == "Done") {
Custom3Field.setRequired(true)
} else {
Custom3Field.setRequired(false)
}
Custom send to mail postfunction script.
Condition and configuration:
issue.projectObject.key == 'PROJECT'
issue.issueType.name == 'Bug'
cfValues['Environment']?.value == 'Production'
E-mail HTML template:
<br><a href="$baseUrl/browse/$issue.key">$baseUrl/browse/$issue.key</a></br>
<br>Status: ${issue.status.name}</br>
<br>$issue.issueType.name $issue.key with priority <% out << issue.priority?.name %>.</br>
<br>Summary: ${issue.summary}</br>
<br>Description: ${issue.description}</br>
<br> ServiceDesk: <% out <<
issue.getCustomFieldValue(com.atlassian.jira.component.ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("ServiceDesk")
) %></br>
<br> Solution description: <% out <<
issue.getCustomFieldValue(com.atlassian.jira.component.ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Solution description")
) %></br>
<br> Test-case description: <% out <<
issue.getCustomFieldValue(com.atlassian.jira.component.ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Test-case description")
) %></br>
Subject template:
##RE-<% out <<
issue.getCustomFieldValue(com.atlassian.jira.component.ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("ServiceDesk")
) %>## $issue.key
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.