Issue Status Name is not Changing Even after the actual workflow is Changed

Harish Patakamuri October 27, 2020

Workflow of the issue type:

Screen Shot 2020-10-27 at 3.21.42 PM.png

Status of the workflow: 

Screen Shot 2020-10-27 at 3.14.13 PM.png

I am trying to change the workflow from "Waiting On App Owner Approval" to "In Progress" with a groovy script when there is a change in transition, it Skips "Waiting for PHI Approver" status if the requested application is not a PHI Application. If you see screenshot 2 it is providing with the option of "Access Granted" Button, which means this already moved to "In Progress" Status according to Screenshot 1, not sure why the Status is not changing from "In Progress"(Status in Screenshot 2). Can someone point me if I am made any mistake? 

 

Here is the code I am using: 

 

import com.atlassian.jira.bc.issue.IssueService
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.IssueInputParametersImpl
import com.atlassian.jira.issue.MutableIssue;
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.event.type.EventDispatchOption
import org.ofbiz.core.entity.GenericValue
import com.atlassian.jira.workflow.WorkflowTransitionUtil;
import com.atlassian.jira.issue.fields.CustomField;
import java.util.Date;
import java.util.ArrayList;
import java.util.stream.Collectors;


def currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def issueManager = ComponentAccessor.issueManager
def issue = issueManager.getIssueObject(event.issue.key)
IssueService issueService = ComponentAccessor.getIssueService()
def actionId = 201
def workflowEntries
def transitionResult
def transitionValidationResult
def StatusId = 6
def customFieldManager = ComponentAccessor.getCustomFieldManager()

if (issue.getIssueType().name == "Application Access Request") {
def status = event.issue.getStatus().getName();
if(status == 'Waiting For PHI Approver'){

def customFieldManager1 = ComponentAccessor.getCustomFieldManager()

def cField = customFieldManager1.getCustomFieldObject("customfield_10628")
def cFieldValue = event.issue.getCustomFieldValue(cField)
String str = cFieldValue.toString()
String str1 = (str) - 'null:' - '1:'
int s = str1.length()
def ApplicationName = (str1.substring(str1.lastIndexOf("[") + 1)).trim() - ']'


if(ApplicationName in ['Strongdm','TriNet']){

def issue1 = event.getIssue() as MutableIssue
ApplicationUser UserName = ComponentAccessor.getUserUtil().getUserObject("timothy.smith")
issue1.setAssignee(UserName);
issueManager.updateIssue(UserName, issue1, EventDispatchOption.DO_NOT_DISPATCH, false)
}
else {

transitionValidationResult = issueService.validateTransition(currentUser, issue.id, actionId,new IssueInputParametersImpl())
//MutableIssue epic
log.error(transitionValidationResult)
if (transitionValidationResult.isValid()) {
transitionResult = issueService.transition(currentUser, transitionValidationResult)
if (transitionResult.isValid())
{ log.error("Transitioned issue $issue through action $actionId") }
else
{ log.error("The transitionValidation is not valid: "
+ transitionValidationResult?.errorCollection?.errorMessages?.join(",")) }
}
else {
log.error("The transitionValidation is not valid: "
+ transitionValidationResult?.errorCollection?.errorMessages?.join(","))
}
}

}
}

2 answers

1 accepted

0 votes
Answer accepted
John Funk
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
October 27, 2020

Hi Harish - Welcome to the Atlassian Community!

I don't know Groovy very well, but why don't you just use Automation for Jira and then don't have to write code? 

Harish Patakamuri October 27, 2020

Thanks, Automation for Jira Working as expected. thanks for your suggestion. 

Like John Funk likes this
1 vote
Yevgen Lasman
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 27, 2020

The code you have posted is for Jira Server/Data Center and will not work in Jira Cloud. As @John Funk has mentioned, using Automation is much better alternative in the Cloud.

Harish Patakamuri October 27, 2020

Sure Yevgen, Thank you. 

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events