Hi All,
I have tried using behaviour and putting my script in the Initialiser and in the server script as well for the corresponding field but the script is not working as Intended
Requirement -
Based on the "Project category" , i need to check "Issue type" and if the issue type is "BUG " then based on that I need to make a "Root Cause" mandatory while creating the issue and editing the issue as well .
At the time of create the scripts functions well but at the time of Editing the issue and changing the Issue type from BUG to other or VICE-VERSA the "Root Cause" field does not become mandatory or non mandatory on the basis of issue type?
Please find the below scripts-
I am using the same script at both the places.
NOTE - The issue what i have observed is when i ma editing the Issue type its ID is not getting changed and it still returns the initial ID of the issue type and hence the IF condition is failing.
----------------Initialiser and Server Script on the Field Issue type ----------------
import com.atlassian.jira.component.ComponentAccessor
import groovy.transform.BaseScript
import static com.atlassian.jira.issue.IssueFieldConstants.*
def field = getFieldByName("Issue Type")
def value1 =field.getValue() as String
def pdv = getFieldById("customfield_11104")
log.warn("Value while editing the issue: "+value1)
if(underlyingIssue.getProjectObject().getProjectCategory()){
if(underlyingIssue.getProjectObject().getProjectCategory().getName().toString().startsWith("NED")){
if (value1 == "10102"){
log.warn('Issue type is BUG at the time of edit')
pdv.setRequired(true)
log.warn("Root cause: ")
}
else
{
pdv.setRequired(false)
log.warn('Issue type is not the BUG at the time of edit')
}
}
else {
pdv.setRequired(false)
log.warn('Project category is not NED at the time of edit')
}
}
Hello @shrikant maheshwari ,
I tried having one behaviours script linked to the issue type field, and it worked.
Are you using only one script ? Do you have the issue type field on the edit screen ?
i am using the same script at both the places. yes i do have the Issue type field on the edit screen .
The problem what i have observed is that when i EDIT the issue and change the Issue type from say task to BUG then the field "Root cause" does not become mandatory as i could see in the logs the ID of Issue type is still of TASK id did not changed to BUG hence the condition is failing.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Ok, so you only face the issue when
Is that correct ? If the issue type is already Bug, the script is working correctly ?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
yes absolutely correct .
So when I am changing the Issue type from say Task to BUG the field "Root cause" does not become mandatory and when i am changing the issue type from BUG to say task then the field is not becoming non-mandatory
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 @shrikant maheshwari ,
I think because the object underlyingIssue does not exist at creation, there might be an issue with your script.
I think you should separate cases when the issue is created and is not, i.e. :
if (!underlyingIssue) {
def field = getFieldByName("Issue Type")
def issueTypeValue = field.getValue() as String
log.warn("issue not created, issue type id is : " + issueTypeValue)
}
else {
def field = getFieldByName("Issue Type")
def issueTypeValue = field.getValue() as String
log.warn("issue type created, issue type id is : " + issueTypeValue)
}
This always returns the right id on my instance.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.