cannot create a valid transition ( to resolved ) in linked issue with GROOVY script runner

jmsantam March 27, 2013

----------------------------------------------------------------------------

It is posible to change an issue link to resolved , ? (change transition)

but, if this action is available but not visible ? ( meaning that I have a condition in workflow )

I can change the resolution in the linked issue, when I resolve the parent issue

but I cannot not change the transition .

where I can get the validation Error ? May I search in LOGS ?

Where I can find a sample to resolve a linked issue ?

here is my code part that is not valid, it works but this code is not executed : (validation is not valid )

// :::::: code part:::::::::::::

// validation of the linked issue transition to resolved

// 2 is the Closed Issue transition ID
// 5 is the Solved Issue transition ID

TransitionValidationResult validationResult = issueService.validateTransition(user, issueLink.getId(), 5, issueInputParameters)

if (validationResult.isValid())
{
IssueResult transitionResult = issueService.transition(user, validationResult);


UpdateValidationResult validationUpdate = issueService.validateUpdate(user, issueLink.getId(), issueInputParameters)


// new way to update interaction ( new API) , not works

issueService.update(user, validationUpdate);

}

complete code :

-----------------------------------------------------------------------------

import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.Issue
import org.apache.log4j.Category
import com.atlassian.jira.issue.link.IssueLink
import com.atlassian.jira.util.JiraUtils
import com.atlassian.jira.workflow.WorkflowTransitionUtil
import com.atlassian.jira.workflow.WorkflowTransitionUtilImpl
import com.atlassian.jira.issue.comments.CommentManager
import com.opensymphony.workflow.WorkflowContext
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.util.ImportUtils
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.IssueInputParameters;
import com.atlassian.jira.issue.IssueInputParametersImpl;
import com.atlassian.jira.bc.issue.IssueService;
import com.atlassian.jira.bc.issue.IssueService.CreateValidationResult;
import com.atlassian.jira.bc.issue.IssueService.UpdateValidationResult
import com.atlassian.jira.user.util.DefaultUserManager
import com.atlassian.jira.issue.link.IssueLinkImpl
import com.atlassian.jira.bc.issue.DefaultIssueService

import com.atlassian.jira.bc.ServiceResultImpl
import com.atlassian.jira.bc.issue.IssueService.TransitionValidationResult
import com.atlassian.jira.issue.IssueInputParametersImpl

import com.atlassian.crowd.embedded.api.User
import com.atlassian.jira.bc.issue.IssueService.UpdateValidationResult
import com.atlassian.jira.bc.issue.IssueService.IssueResult
import com.atlassian.jira.ComponentManager
import com.atlassian.jira.bc.issue.IssueService

import java.util.*;
import org.apache.log4j.Logger;

import com.atlassian.core.ofbiz.CoreFactory;
import org.ofbiz.core.entity.GenericValue;
import org.ofbiz.core.entity.GenericDelegator;
import org.ofbiz.core.entity.GenericEntityException;
import org.ofbiz.core.entity.EntityUtil;

import javax.servlet.http.HttpServletRequest;

import com.atlassian.jira.ofbiz.OfBizDelegator;
import com.atlassian.jira.ComponentManager;

import webwork.action.ActionContext;


// we create the linkmanager to manage links in the interaction ( escalated interaction (PO office)--> linked --> new ticket (ohim) )

def linkMgr = componentManager.getIssueLinkManager()

// uncomment this line to test the script in script runner
MutableIssue issue = componentManager.getIssueManager().getIssueObject("CTM-177")


// we create a list to get the list of linked escalated interactions , it will be only one, so we dont need a bucle
def link_list = []

// we get the link of ticket ( the issue.id where we are working on )
link_list = linkMgr.getInwardLinks(issue.id)

// we get the first object of the list, get(0) that will be the interaction
issueLink = link_list.get(0).getSourceObject()

// we change the resolution of the escalated interaction to 8 (solved)
issueLink.setResolutionId("8")

// not used only an example to change TITLE too
//issueLink.setSummary("Escalated interaction SOLVED")


// new way to update interaction ( new API) , not works

def com.atlassian.crowd.embedded.api.User user = ComponentManager.instance.jiraAuthenticationContext.getLoggedInUser()

def issueService = ComponentManager.getInstance().getIssueService()

def issueInputParameters = issueService.newIssueInputParameters(ActionContext.getParameters())

TransitionValidationResult validationResult = issueService.validateTransition(user, issueLink.getId(), 5, issueInputParameters)


if (validationResult.isValid())
{
IssueResult transitionResult = issueService.transition(user, validationResult);


UpdateValidationResult validationUpdate = issueService.validateUpdate(user, issueLink.getId(), issueInputParameters)

// 2 is the Closed Issue transition ID
// 5 is the Solved Issue transition ID


// new way to update interaction ( new API) , not works

issueService.update(user, validationUpdate);

}

else {

log.debug("wrong validation : " + validationResult);
System.out.println("Hola mundo");

}

// System.out.println(validationResult);


// old way to update the interaction - this works

ComponentManager.getInstance().getIssueManager().updateIssue(user, issueLink, EventDispatchOption.DO_NOT_DISPATCH, true)
ComponentManager.getInstance().getIndexManager().reIndex(issueLink);

1 answer

2 votes
Heidi Hunter March 27, 2013

If I am understanding correctly, you want to run a workflow step that resolves the linked issue when the "source" issue is resolved, and set the resolution value. First, I'll try to answer your questions:

It is posible to change an issue link to resolved , ? (change transition)

but, if this action is available but not visible ? ( meaning that I have a condition in workflow )

Yes, it is possible to run a workflow step on the linked-to issue object, but only if you have permission to do so. IssueService enforces the workflow rules, screens, and project permissions configured in JIRA, so you can only do in code what you would be able to do in the interface. So if the action is not "visible" for the linked issue because of a workflow condition, validation will fail. The current user in the script context must also have permission.

The same is true for updating (editing) issues. The user must have "Edit Issues" permission on the project in order to call update(). To set the resolution, the user must additionally have "Resolve Issues" permission.

where I can get the validation Error ? May I search in LOGS ?

Inspect the contents of the ErrorCollection from the validation result, i.e. validationResult.errorCollection. You would have to log this yourself to see it in the application log. (See org.apache.log4j.Logger and this section of the Script Runner docs)

My suggestion would be to review the workflow conditions and user permissions - make sure that the users running the workflow which triggers this script are also able to do workflow on and resolve the linked issues.

The script could do the actual resolution in one of two:

Solution A.

1. Set the resolution via IssueService.update. The resolution field must be included on the Edit screen in this case.

2. Transition the issue

Solution B.

1. Create a workflow transition that captures the resolution - the resolution field must be on the associated screen.

2. Transition the issue, passing the resolution value in the IssueInputParameters.

I recommend Solution B.

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.
March 28, 2013

Great answer. With respect to permissions in the UI and the issue service, Heidi is spot on, but, you can set some other user that does have permissions if you want to do an action that the user could not.

jmsantam April 3, 2013

thanks, sorry for the delay in response, I was on holidays

Thank you for the detailed answer :)

Yes it seems that Is a problem of workflow (validation)

I can change resolution but not the transition, ( Its ok for me for the moment )

we are using in fact 2 different workflows : ( it was an idea of design of other guy )

So I guess that this is the problem :), I have the permissions ok, but something is missing.

workflow1 (users A) -> transfers (clones) a typeA Issue to workflow2 ( usersB )

a duplicated new ticket is created to usersB (the type of ticket changes).

when the cloned ticket is solved by UsersB (workflow2) , then the resolution of the Origin (parent)

is changed. and we send a notification.

regards,

Suggest an answer

Log in or Sign up to answer