Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Error popup window with script listener- updated issue

Dan27
Contributor
July 23, 2018

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

}

}

1 answer

0 votes
Danyal Iqbal
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 23, 2018

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

Dan27
Contributor
July 23, 2018

@Danyal Iqbal , I need to leave it like this.. there isn't an option to do it by listener ?

Danyal Iqbal
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 23, 2018

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.

Dan27
Contributor
July 23, 2018

@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? 

Danyal Iqbal
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 23, 2018

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.

Dan27
Contributor
July 23, 2018

@Danyal Iqbal I mean the version was before the updated event that call this script listener..

Danyal Iqbal
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 23, 2018

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.

Dan27
Contributor
July 23, 2018

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.

Danyal Iqbal
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 24, 2018

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.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events