Hi,
I try to create a pop up error window with script listener
(while trying to change 'fix version' of child, we Have to ensure the father is in the same version - so a dialog window will open and the change didn't save).
I try with this code without success:
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.project.version.Version
import com.onresolve.scriptrunner.runner.util.UserMessageUtil
import javax.ws.rs.core.Response
import com.onresolve.scriptrunner.runner.rest.common.CustomEndpointDelegate
import com.atlassian.jira.security.roles.ProjectRoleManager;
import javax.ws.rs.core.Response
import javax.servlet.http.HttpServletRequest;
import groovy.transform.BaseScript
import javax.ws.rs.core.MediaType
import javax.ws.rs.core.MultivaluedMap
@BaseScript CustomEndpointDelegate delegate
IssueManager issueManager = ComponentAccessor.getComponent(IssueManager.class)
//test
Issue issue = issueManager.getIssueObject("WBL-49179");
//Issue updatedIssue = event.getIssue();
def issueType=issue.getIssueType().name;
if (issueType=="Story" || issueType=="Bug-Internal" || issueType=="Bug-Customer" || issueType=="RFE"
|| issueType=="Sub-Test"
|| issueType=="Sub-Bug")
{
//Get fix versions of issue
Collection<Version> fixVersions = new ArrayList<Version>();
fixVersions = issue.getFixVersions();
//Get Epic Link Key
def epic = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Epic Link");
def epicKey = issue.getCustomFieldValue(epic);
//Get Epic issue
Issue epicIssue = issueManager.getIssueObject(epicKey.toString());
//Get Fix Versions of epic issue
Collection<Version> fixVersionsEpic = new ArrayList<Version>();
fixVersionsEpic = epicIssue.getFixVersions();
def currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
// Get the changed field
def exampleField = getFieldById(getFieldChanged());
if (fixVersions!=fixVersionsEpic)
{
Here the window popup should be
}
}
May I suggest the following workaround:
* Remove the fixversion from the edit screen. It should only be present on the screen for the relevant transition e.g Assign fixVersion. Sooner rather than later, you will need to control who can or cannot assign a fixVersion.
* Write a condition to enforce same fixVersion for parent and child. see https://jamieechlin.atlassian.net/wiki/spaces/GRV/pages/1212424/Conditions
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Sure, you can do it, but it is not a best practice. check out the UserMessageUtil.*e.,g
import com.onresolve.scriptrunner.runner.util.UserMessageUtil
// Either
UserMessageUtil.success("Created two sub-tasks to be approved")
// or
UserMessageUtil.warning("Failed to push issue to downstream system, will try again later")
// or
UserMessageUtil.error("Failed to reopen all linked issues")
I would recommend the proper way though :) Good soldiers chooses their battles wisely.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Danyal Iqbal Thanks!
2 things:
1. the warning message appeared 4 or 5 timer instead 1.
2. How can I keep the version before the update?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
the warning message appeared 4 or 5 timer instead 1.
--probably due to mulitple fixversions. FixVersion is an array.
2. How can I keep the version before the update?
--save it in a variable and issue.setfixversion([version]) in the if block.
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.
sorry, but that makes no sense. You want to disallow dissimilar fixversions but you want to assign the original (different ) fixversion to the child again.
it might make more sense to copy the fixversion from the parent issue while creating the subtask (or write a bahaviour to prepopulate the subtask fixsversion ) and make it completely uneditable in the subtask.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
No, I would like that if someone wants to change the version of an issue (from Y to X), but the parent has version Y, an error popup will displayed.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
did you try issue.setfixversion([fixVersion_parent ]) in the if block to set the sane fix version on the child if the two are not equal.
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.