Hello all :)
In 'Epic workflow' , Change parent , I would like to insert validator,
that will compare the Epic fix version to the new Feature (that chose in the change parent window) fix version.
I try this code in the scripted (groovy) validator without success:
import com.atlassian.jira.project.version.Version
//Get Fix Versions of epic issue
Collection<Version> fixVersions = new ArrayList<Version>();
fixVersions = issue.getFixVersions();
def feature = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Parent Feature Key");
def featureValue = issue.getCustomFieldValue(feature);
def featureKey=featureValue.toString().substring(0,7);
//Get Feature issue
Issue featureIssue = issueManager.getIssueObject(featureKey.toString());
//Get Fix Versions of Feature parent
Collection<Version> fixVersionsFeature = new ArrayList<Version>();
fixVersionsFeature = featureIssue.getFixVersions();
//Validator
if(fixVersions[0]!=fixVersionsFeature[0])
{
}
I Daniel,
can you clarify your request? Is "Change parent" a transition of the Epic workflow? Also, you mention a "new Feature", what is that? And what is the "Parent Feature Key" field? A custom text field? Some other type?
Thanks,
David
Hi David @David Fischer ,
Is "Change parent" a transition of the Epic workflow? - Yes
You press change parent and the epic move from the current feature to the new one (you choose in the change parent window)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Daniel,
if I understand correctly, you link Epics to their "parent" Feature using a custom field.
What is the name and type of this custom field (on the "Custom Fields" page)? Are you using Jira Portfolio? If so, the field would be "Parent Link". If not, how are you storing the "pointer" to the parent Feature?
The actual code will be much simpler than what you wrote (which I assume you assembled from snippets found on the web that were meant for ScriptRunner instead), but I need to understand your configuration in order to help you.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@David Fischer , you understood correctly.
In the workflow I have this option of 'change parent'- In this screen, the user will pick a different feature to be the parent of the issue (epic).
Then I would like to put the validator that will check 2 custom fields of the spesific issue (epic), If 'Fix version' custom field (version picker) is equals to 'Parent Fix Version' (Text field)- this custom field is calculated by script field and tell the 'fix version' custom field value of the linked feature.
If yes - The new feature is saved.
If not - An error will shown and the change parent won't happened .
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Unfortunately, you still didn’t answer my question: what is that field that links the Epic to its parent feature? I need it’s name and it’s type, as they appear on the Custom Fields screen.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @David Fischer .
Like I said, you don't need the parent link, because the value ' fix version' is already taken from the parent , and saved in the issue custom filed named 'Parent Fix Version'.
Anyway , the parent link named Parent Feature , and it's a text field.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Daniel,
you do need the new parent link to access the fix version of the new parent, don't you? If the user is changing the parent feature, when the Validator runs, the "Parent Fix Version" field won't yet be updated (I assume it's updated by a post-function, which will run after the validators). Unless the Parent Fix Version field is a calculated text custom field (using JMCF or ScriptRunner)?
But in your attempt to write a script, you did try to use the Parent Feature field (although you called it "Parent Feature Key", so which is the correct one?). So I'm confused.
Also, in your script, you are using the built-in Fix Version/s field, not a "Fix Version" custom version picker field. Which one do you actually need?
Anyway, let's assume the "Parent Fix Version" field is not a calculated custom field but a regular text field that will get updated by a post-function in the same transition. In that case, you can't rely on its value in the Validator and you have to go to the parent feature.
Here's a starting point for the script:
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
//get the parent feature
def featureKey = issue.get("Parent Feature Key")
if (!featureKey)
return true;
Issue feature = ComponentAccessor.issueManager.getIssueObject(featureKey)
if (!feature)
return true;
return feature.fixVersions == issue.fixVersions;
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks @David Fischer !!!
I used your code and it helped a lot! My final code is:
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.IssueManager
//get the parent feature issue
Issue featureT = ComponentAccessor.issueManager.getIssueObject('Parent Feature')
//if feature and epic fix version is the same
return featureT.fixVersions == issue.fixVersions;
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 actually see how that could work, since ComponentAccessor.issueManager.getIssueObject() takes an issue key, and “Parent FEature” isn’t exactly an issue key...
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
It might be a "real" key to you, but it's not an issue key, which is what you need to make the code work.
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.