Hi ,
We created one script to auto-change status when ticket is created.
As the result , ticket status is abnormal that its status is not changed but have transition record indeed …
Here is script as we wrote.
//---------------------------------------------------------------------------
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.workflow.WorkflowManager;
import com.opensymphony.workflow.loader.StepDescriptor;
import com.opensymphony.workflow.loader.ActionDescriptor;
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.status.Status;
import com.atlassian.jira.bc.issue.IssueService;
import com.atlassian.jira.issue.IssueInputParametersImpl;
import com.atlassian.core.util.ClassLoaderUtils;
def currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
private void sendPost(String ticket_id, int action_id)
{
String url = getUrl() + “/Interface/Trust/JiraService.svc/json/Issue/” + ticket_id + “/Transition”;
URL obj = new URL(url);
HttpURLConnection con = (HttpURLConnection) obj.openConnection();
//add reuqest header
con.setRequestMethod("POST");
con.setRequestProperty("DomainAccount", "austin_lee");
con.setRequestProperty("Content-Type", "application/json; charset=UTF-8");
// Send post request
con.setDoOutput(true);
OutputStream os = con.getOutputStream();
os.write(action_id.toString().getBytes("UTF-8"));
os.close();
int responseCode = con.getResponseCode();
BufferedReader bufferdReader = new BufferedReader(new InputStreamReader(con.getInputStream()));
String inputLine;
StringBuffer response = new StringBuffer();
while ((inputLine = bufferdReader.readLine()) != null) {
response.append(inputLine);
}
bufferdReader.close();
log.warn(response.toString());
//return response.toString();
}
private String getUrl()
{
Properties properties=new Properties();
InputStream iStream = ClassLoaderUtils.getResourceAsStream(“jarvis-setting.properties”, this.getClass());
if (iStream != null)
{
properties.load(iStream);
}
return properties.getProperty(“api.url”)
}
Issue issue = event.getIssue();
if (issue.getIssueType().name == “Hybrid Support”) {
if (issue.getStatus().getName() == “To be Assigned”)
{
String issueId = issue.getKey();
WorkflowManager workflowManager = ComponentAccessor.getWorkflowManager();
Status status = issue.getStatus();
StepDescriptor currentStep = workflowManager.getWorkflow(issue).getLinkedStep(status);
List actions = currentStep.getActions();
for (ActionDescriptor actionDescriptor : actions) {
if (actionDescriptor.getName() == “Process”){
Thread.sleep(20000)
int actionId = actionDescriptor.getId()
IssueService issueService = ComponentAccessor.getIssueService()
def transitionValidationResult = issueService.validateTransition(currentUser, issue.id, actionId, new IssueInputParametersImpl())
if (transitionValidationResult.isValid()) {
def transitionResult = issueService.transition(currentUser, transitionValidationResult)
if (transitionResult.isValid())
{
log.debug(“Transitioned issue $issue through action $actionId”)
}
else
{
log.debug(“Transition result is not valid”)
}
}
else
{
log.debug(“The transitionValidation is not valid”)
}
}
}
}
}
//-------------------------------------------------------------------------------------
Our jira version is 7.7.1
Please anyone kindly support us.
Thank you very much