Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

How to change Issue Status via C# API

Chris
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
October 13, 2023

Hi,

 

I'm using Atlassian.Jira.dll and have already connected successfully.

 

I can fetch an issue without problems and have also managed to leave a comment on it via API. Now I need to update and set the issue status to "xyz". How can I do that?

 

I've already tried issue.SetPropertyAsync(), jira.Issues.UpdateIssueAsync(), among other things. ChatGPT also wasn't of any help either.

I think UpdateIssueAsync() is the right way to go, but I can't figure out how to set the issue status. issue.Status is read only.

 

Can anybody help? Here's the code snippet:

 

// Jira Client
Atlassian.Jira.Jira jira = GetJiraClient();

if (jira == null)
     return;

// Get relevant issues
string jql_query = $"project = \"12345\"";
IPagedQueryResult<Issue> jira_issues = jira.Issues.GetIssuesFromJqlAsync(jql_query).Result;

if (jira_issues == null || !jira_issues.Any())
     return;

string new_status = "New Status";
foreach (Issue issue in jira_issues)
{
     // Change issue values here

     // Update issue status here
     jira.Issues.UpdateIssueAsync(issue);
}

2 answers

1 accepted

0 votes
Answer accepted
Chris
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
November 7, 2023

Figured it out myself.

 

The way to do this is to set the transition rather than the status:

 

jira_issue.WorkflowTransitionAsync(new_status).GetAwaiter().GetResult();

 

I'm honestly quite disappointed that nobody here was able to provide this simple fix. I surely can't be the first person ever to change a jira status via the API.

0 votes
Fabrício Guilherme Borges da Silva
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
July 11, 2024

Você pode atualizar os status por meio do WorkflowTransitionAsync usando a string correspondente ao seu status de destino ex.: Feito, Cancelado etc.

Abaixo segue o código que utilizamos 

{code}

public async Task<bool> AtualizaStatus(Issue issue, string statusDestino, string? comentario, string? pacote)
{
if (issue == null) return false;

await issue.WorkflowTransitionAsync(statusDestino);

if (!string.IsNullOrEmpty(comentario))
{
await issue.AddCommentAsync(comentario);
}

return true;
}

{code}

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
PREMIUM
TAGS
AUG Leaders

Atlassian Community Events