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.
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());
}
}
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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":{}}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
What version of Jira are you using? and are you using Automation for Jira to do the automation?
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.