Missed Team ’24? Catch up on announcements here.

×
Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

How to add existing issue to sprint? I am getting error "Number value expected as the Sprint id."

Arvind Jagtap September 7, 2020

I want to add existing Jira issue to sprint. I got the sprint from RapidView

// get the current sprint
GreenHopperClient gh = new GreenHopperClient(jira);
System.out.println(gh.getClass().toString());
/* Retrieve all Rapid Boards */
List<RapidView> allRapidBoards = gh.getRapidViews();
/* Retrieve a specific Rapid Board by ID */
RapidView board = gh.getRapidView(2915);
/* Print the name of all current and past sprints */
List<Sprint> sprints = board.getSprints();
// get the last sprint in the list
Sprint s = sprints.get(sprints.size()-1);

List<String> lstSprints = new ArrayList<String>();
lstSprints.add(s.getId());

Issue iss = jira.getIssue("NGMTS-15434");
iss.update().field("customfield_10102", lstSprints).execute();

This code gives me following error.

Failed to update issue NGMTS-15434
400 400: {"errorMessages":["Number value expected as the Sprint id."],"errors":{}}

I tried sending the list of Integers which didn't work. What can be the problem here? Please help me in the understanding this problem.

 

3 answers

1 accepted

0 votes
Answer accepted
Arvind Jagtap October 4, 2020

I couldn't solve the above mention problem. So I tried alternate approach of using REST API instead of JiraClient and it worked. Following Java code successfully adds the issue in the given sprint.

public static void addIssueToSprint(String strIssueKey, int nSprintNo)
{
try {
// set the URL and connection
URL urlForGetRequest = new URL("https://<hostname>/rest/api/2/issue/" + strIssueKey);
HttpURLConnection connection = (HttpURLConnection) urlForGetRequest.openConnection();
// set the method as PUT as the request is to update the Issue
connection.setRequestMethod("PUT");
connection.setDoOutput(true);
connection.setRequestProperty("Content-Type", "application/json");
connection.setRequestProperty("Accept", "application/json");
connection.setInstanceFollowRedirects( false );
// set the authorization data
String auth = "<username>:<password>";
byte[] encodedAuth = Base64.encodeBase64(auth.getBytes(StandardCharsets.UTF_8));
String authHeaderValue = "Basic " + new String(encodedAuth);
connection.setRequestProperty("Authorization", authHeaderValue);

// set the payload with sprint number
String jsonInputString = "{\r\n" +
"\"fields\":{\r\n" +
"\"customfield_10102\":"+ nSprintNo +"\r\n" +
"}\r\n" +
"}";

OutputStreamWriter osw = new OutputStreamWriter(connection.getOutputStream());
osw.write(jsonInputString);
osw.flush();
osw.close();
if(connection.getResponseCode() >= 400)
System.err.println("Couldn't add the issue to sprint: " + connection.getResponseCode());
else
System.out.println("Issue added to the sprint: " + nSprintNo);
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
System.err.println("Couldn't add the issue to sprint: " + e.getMessage());
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
System.err.println("Couldn't add the issue to sprint: " + e.getMessage());
}
}

0 votes
Sherry Goyal
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
September 7, 2020

@Arvind Jagtap 

Hello!

From a quick glance, seems like 

            List<String> lstSprints = new ArrayList<String>(); 

should be of "long" type. Maybe give it a shot and try solving your problem.

 

Cheers
Sherry

Arvind Jagtap September 7, 2020

Since ArrayList doesn't hold primitive data types, I tried following code to create a list

Long lSprintNo = new Long(s.getId());
List<Long> lstSprints = new ArrayList<Long>();
lstSprints.add(lSprintNo);
iss.update().field("customfield_10102", lstSprints).execute();

But it is giving the same error as mentioned below.

Failed to update issue NGMTS-15434
400 400: {"errorMessages":["Number value expected as the Sprint id."],"errors":{}}

Sherry Goyal
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
September 7, 2020

I would suggest to do try bunch of things:

1. Try without putting into list. Directly:

iss.update().field("customfield_10102", lSprintNo).execute();

2. Try setting sprint value to sprint fields:

iss.update().field("Sprint", sprint.getName()).execute();

3. Similar thing was achieved here: https://community.atlassian.com/t5/Jira-Software-questions/Programatically-Update-the-Sprint-Field-in-Issues/qaq-p/722007

See if this helps you in anyway

or

else wait for the subject matter expert to give some advice on this. 

Thanks
Sherry

Arvind Jagtap September 8, 2020

Thanks Sherry for looking into it and suggesting various options.

I have tried initially assigning the sprint number directly instead of list and I got error "Field expects an Iterable value". Since then I am trying to set the list.

That error is also applicable to the second option you suggested. I also read at some other place that sprint number should be specified instead of name as there can be multiple sprints with same name.

I saw the script provided in the link which has completely different object model. I couldn't find these objects (GreenHopperBean, SprintManager, etc.) in JiraClient library. So I couldn't use this script. I am using Java which is different than this scripting language.

So not able to proceed further and will wait for response from subject matter expert. Anyway thanks for your quick responses and the help.

0 votes
Curt Holley
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
September 7, 2020

What version of Jira are you using? and are you using Automation for Jira to do the automation?

Arvind Jagtap September 7, 2020

I am using Jira v8.5.3. While selecting the category, I thought Jira Automation is a category and didn't know that it is a separate product. I am writing a program to automate Jira user interaction using the JiraClient library.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events