Hi,
I've problem with script below:
import org.apache.log4j.Level
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.bc.issue.IssueService
import com.atlassian.jira.issue.IssueInputParametersImpl
import com.atlassian.jira.workflow.JiraWorkflow
import com.atlassian.jira.workflow.WorkflowManager
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.customfields.manager.OptionsManager
import com.atlassian.jira.issue.customfields.option.Option
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.jira.security.groups.GroupManager
CustomFieldManager cfm = ComponentAccessor.getCustomFieldManager();
DefaultIssueChangeHolder changeHolder = new DefaultIssueChangeHolder();
CustomField lastClientCommentCf = cfm.getCustomFieldObject(11200L)
def commentManager = ComponentAccessor.getCommentManager()
def issue = event.issue
def commentList = commentManager.getComments(issue).sort{it.getCreated()}
GroupManager gm = ComponentAccessor.getGroupManager()
def comment = commentManager.getLastComment (issue)
// MODYFIKACJA-------------------------------------------------------
def currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def issueManager = ComponentAccessor.issueManager
def issue2 = issueManager.getIssueObject(event.issue.key)
IssueService issueService = ComponentAccessor.getIssueService()
def actionId = 281 // change this to the step that you want the issues to be transitioned to
def transitionValidationResult
def transitionResult
def customFieldManager = ComponentAccessor.getCustomFieldManager()
log.debug("The issue type is: " + issue2.getIssueType().name)
log.setLevel(Level.DEBUG)
//---------------------------------------------------------------------
//log.error("Dodanie znacznika do komantarzy")
//log.error((gm.isUserInGroup(comment.getUpdateAuthorApplicationUser(), "jira-servicedesk-users")) || (gm.isUserInGroup(comment.getUpdateAuthorApplicationUser(), "Jsu-partners-team")) || (gm.isUserInGroup(comment.getUpdateAuthorApplicationUser(), "jira-software-users")))
if(comment && ((gm.isUserInGroup(comment.getUpdateAuthorApplicationUser(), "jira-servicedesk-users")) || (gm.isUserInGroup(comment.getUpdateAuthorApplicationUser(), "Jsu-partners-team")) || (gm.isUserInGroup(comment.getUpdateAuthorApplicationUser(), "jira-software-users")))){
lastClientCommentCf.updateValue(null,issue,new ModifiedValue(issue.getCustomFieldValue(lastClientCommentCf),null),changeHolder);
}
else
{
lastClientCommentCf.updateValue(null,issue,new ModifiedValue(issue.getCustomFieldValue(lastClientCommentCf),findCustomFieldOption("11200L","T")),changeHolder);
//---------
log.info("znacznik")
transtionIssue(issue, currentUser, 281)
log.info("znacznik2")
//----------
}
private def findCustomFieldOption(String customFieldId, String optionString) {
OptionsManager optionsManager = ComponentAccessor.getOptionsManager();
List<Option> options = optionsManager.findByOptionValue(optionString);
if (options.iterator().hasNext()) {
Option option = options.iterator().next();
return option
} else
return optionString;
}
void transtionIssue(Issue issue, ApplicationUser user, int transitionId)
{
//def currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def issueManager = ComponentAccessor.issueManager
IssueService issueService = ComponentAccessor.getIssueService()
def actionId = transitionId // change this to the step that you want the issues to be transitioned to
def transitionValidationResult
def transitionResult
def customFieldManager = ComponentAccessor.getCustomFieldManager()
log.debug("Function transtionIssue -> The issue type is: " + issue.getIssueType().name)
transitionValidationResult = issueService.validateTransition(user, issue.id, actionId,new IssueInputParametersImpl())
if (transitionValidationResult.isValid()) {
transitionResult = issueService.transition(user, transitionValidationResult)
}
log.info("znacznik3")
}
At the end I've got function to change status by transition, but it dosen't work and I don't know why :(
Logs:
Time (on server): Mon Oct 21 2019 19:30:49 GMT+0200 (czas środkowoeuropejski letni)
The following log information was produced by this execution. Use statements like:log.info("...") to record logging information.
2019-10-21 19:30:49,500 DEBUG [runner.AbstractScriptRunner]: The issue type is: Zgłoszenie PLZAM 2019-10-21 19:30:49,507 INFO [runner.AbstractScriptRunner]: znacznik 2019-10-21 19:30:49,507 DEBUG [runner.AbstractScriptRunner]: Function transtionIssue -> The issue type is: Zgłoszenie PLZAM
As we can see "znacznik2" and "znacznik3" did not appear in the logs.
Everything works fine until this point:
lastClientCommentCf.updateValue(null,issue,new ModifiedValue(issue.getCustomFieldValue(lastClientCommentCf),findCustomFieldOption("11200L","T")),changeHolder);
The field value is set here, and then I would like to do transition 281.
Hi
I think you can use WorkflowTransitionUtil in script runner listener if you need to update issue status
Below is code example, try something like this:
import com.atlassian.jira.workflow.WorkflowTransitionUtil;
import com.atlassian.jira.workflow.WorkflowTransitionUtilImpl;
import com.atlassian.jira.util.JiraUtils;
...
WorkflowTransitionUtil workflowTransitionUtil = ( WorkflowTransitionUtil ) JiraUtils.loadComponent( WorkflowTransitionUtilImpl.class );
...
MutableIssue issueToUpdate = (MutableIssue) event.issue;
ApplicationUser currentUser=event.getUser();
int actionID=999; //your transition ID
...
workflowTransitionUtil.setIssue(issueToUpdate);
workflowTransitionUtil.setUserkey(currentUser.getKey());
workflowTransitionUtil.setAction (actionID) //transition or action ID
// Validate and transition issue
workflowTransitionUtil.validate();
workflowTransitionUtil.progress();
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.