Workflow of the issue type:
Status of the workflow:
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(","))
}
}
}
}
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?
Thanks, Automation for Jira Working as expected. thanks for your suggestion.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.