Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Move Issue using groovy script runner not working properly

Nir Zolotorevsky
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.
October 11, 2015

We have groovy post function which is run on create issue event from script runner addon. It is using "com.atlassian.jira.web.bean.MoveIssueBean" to move issue from one project to another when some condition met.

The issue created correctly in the destination project.

But result screen after performing this action is corrupted!!!

Corrupted result screen depends from where we start create operation:

1. First result on move is “grayed screen” when creating bug from dashboard or from project main screen: refresh opens same page as was before, no indication that bug created but created bug exists in correct place. 2. Second result when creating bug from some open issue: in background original page in front new created issue after move but small and ugly.

3. Third result from admin screen: everything is OK, and after creation new bug is opened as needed. 

Will really appreciate if some groovy/script runner expert could help us with this bug with "MoveIssueBean" API.

Attached groovy method for moving issue:

public void moveIssueToAnotherProject(String newProjectName, IssueType  newIssueType, Status newStatus, MutableIssue targetIssue, String IPversionToSet) {
        try {
            log.warn("targetIssue: " + targetIssue )
            log.warn("newStatus: " + newStatus.getName() )
            
            Project projectObj=getProjectFromName(newProjectName)
            log.warn("newProjectName: " + projectObj )
            CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager()
            VersionManager versionmanger =ComponentAccessor.getVersionManager();
            CustomField cf = customFieldManager.getCustomFieldObjectByName("Version")
            log.warn("newversion: " + IPversionToSet)
            Version newversion=versionmanger.getVersion(projectObj.id, IPversionToSet)
            Collection<Version> newverCol=new ArrayList<Version>()
            newverCol.add(newversion)
            log.warn("newversionObject: " + newverCol)
//            IssueChangeHolder changeHolder = new DefaultIssueChangeHolder()
            if(cf!=null)
            {
//                Object value = cf.getValue(targetIssue);
//                ModifiedValue modifiedValue=new ModifiedValue(value, newverCol)
//                cf.updateValue(null, targetIssue, modifiedValue,changeHolder)
                targetIssue.setCustomFieldValue(cf, newverCol)
                def cfv = targetIssue.getCustomFieldValue(cf)
                log.warn("customfield value after change: " + cfv)
            }
            MoveIssueBean moveIssueBean = new MoveIssueBean(ComponentAccessor.getConstantsManager(), ComponentAccessor.getProjectManager())
            log.warn("projectObj.id: " + projectObj.id )
            moveIssueBean.getFieldValuesHolder().put(IssueFieldConstants.PROJECT, projectObj.id)
            log.warn("newIssueType.id: " + newIssueType.id )
            moveIssueBean.getFieldValuesHolder().put(IssueFieldConstants.ISSUE_TYPE, newIssueType.id)
            
    
            
            
            log.warn("curIssue.id: " + targetIssue.getId())
            moveIssueBean.setIssueId(targetIssue.getId())
            log.warn("newStatus.id : " + newStatus.id )
            moveIssueBean.setTargetStatusId(newStatus.id )
            log.warn("curIssue.key : " + targetIssue.getKey())
            moveIssueBean.setSourceIssueKey(targetIssue.getKey())
            log.warn("targetIssue: " + targetIssue)
            moveIssueBean.setUpdatedIssue(targetIssue)
            ActionContext.getSession().put(SessionKeys.MOVEISSUEBEAN, moveIssueBean)
            log.warn ("after action context move Issue Beans")
            MoveIssueUpdateFields moveIssueUpdateFields = new MoveIssueUpdateFields(
                    ComponentAccessor.getSubTaskManager(),
                    ComponentAccessor.getConstantsManager(),
                    ComponentAccessor.getWorkflowManager(),
                    ComponentAccessor.getFieldManager(),
                    ComponentAccessor.getFieldLayoutManager(),
                    ComponentAccessor.getIssueFactory(),
                    ComponentAccessor.getFieldScreenRendererFactory(),
                    ComponentAccessor.getComponentOfType(CommentService.class),
                    ComponentAccessor.getComponentOfType(IssueSecurityHelper.class),
                    ComponentAccessor.getUserUtil()
            )
            log.warn ("after moveIssueUpdateFields")
            MoveIssueConfirm moveIssueConfirm = new MoveIssueConfirm(
                    ComponentAccessor.getSubTaskManager(),
                    ComponentAccessor.getComponentOfType(AttachmentManager.class),
                    ComponentAccessor.getConstantsManager(),
                    ComponentAccessor.getWorkflowManager(),
                    ComponentAccessor.getFieldManager(),
                    ComponentAccessor.getFieldLayoutManager(),
                    ComponentAccessor.getIssueFactory(),
                    ComponentAccessor.getFieldScreenRendererFactory(),
                    ComponentAccessor.getComponentOfType(CommentService.class),
                    ComponentAccessor.getComponentOfType(IssueSecurityHelper.class),
                    ComponentAccessor.getIssueManager(),
                    ComponentAccessor.getUserUtil()
            )
            log.warn ("after moveIssueConfirm")
            JiraSystemProperties.getInstance()
            log.warn ("after JiraSystemProperties")
            moveIssueUpdateFields.setId(targetIssue.getId())
            log.warn ("after moveIssueUpdateFields.setId(targetIssue.getId())")
            Method privateUpdateFieldsDoExecute = MoveIssueUpdateFields.class.getDeclaredMethod("doExecute")
            log.warn ("after privateUpdateFieldsDoExecute")
            privateUpdateFieldsDoExecute.setAccessible(true)
            log.warn ("after setAccessible")
            privateUpdateFieldsDoExecute.invoke(moveIssueUpdateFields)
            log.warn ("after invoke")
            moveIssueConfirm.setId(targetIssue.getId())
            log.warn ("after setId")
            Method privateIssueConfirmDoExecute = MoveIssueConfirm.class.getDeclaredMethod("doExecute")
            log.warn ("after privateIssueConfirmDoExecute")
            privateIssueConfirmDoExecute.setAccessible(true)
            log.warn ("after privateIssueConfirmDoExecute.setAccessible(true)")
            privateIssueConfirmDoExecute.invoke(moveIssueConfirm)
            log.warn ("after privateIssueConfirmDoExecute.invoke(moveIssueConfirm)")
            CoreTransactionUtil.commit(true)
            log.warn ("after commit")
        }
        catch (Exception e) {
            log.error("move issue failed " + e.message)
        }
    }

 

Thanks

8 answers

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

0 votes
Nir Zolotorevsky
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.
October 12, 2015

The difference in this 2 cases are that when I create from Overview panel, I should stay in overview panel and get a pop up saying that issue was created with a link. This is not working!! After refresh I stay on Overview panel but there is no indication that new issue is created!!!!! From Administration Panel the new issue should appear on screen -> this works OK

0 votes
JamieA
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.
October 11, 2015

And what's the difference in those two scenarios... just that one opens in full screen and one in a dialog. So are the problems just cosmetic, ie if you create the issue in a dialog, then refresh it, does it work as expected?

0 votes
Nir Zolotorevsky
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.
October 11, 2015

No, I press "create issue" button when I am in Project->administration panel everything works perfect. When I am on Overview panel and press "create" button I get all described above misbehavior.

0 votes
Vijay Khacharia
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.
October 11, 2015

May be its the order in which the post-functions are ordered. Are you making the groovy call after the original issue is created and indexed or before? Normally on create transition, groovy should be run as last post-function.

Nir Zolotorevsky
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.
October 11, 2015

My groovy post function is the last one

0 votes
JamieA
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.
October 11, 2015

what do you mean by that, you mean run it from the script console?

0 votes
Nir Zolotorevsky
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.
October 11, 2015

I agree that this is user contributed code, but do you have any clue how to fix this. And Why everything works perfect when I start action from admin panel?

0 votes
JamieA
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.
October 11, 2015

Also note this is not a problem with the plugin but with user-contributed code.

0 votes
JamieA
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.
October 11, 2015

This is not an easy problem... if this worked and always worked, it would be in as a standard script post-function.

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

TAGS
AUG Leaders

Atlassian Community Events