Forums

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

How to get Open Sprints created before an year ago using SIL

Bhargavi Vasa
Contributor
March 9, 2023

Get Open Sprint id's created before an year ego using SIL script

1 answer

0 votes
Anna Hryhoruk _Appfire_
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 10, 2023

Hello @Bhargavi Vasa ,

You can try something like this: 

string format = "yyyy"; //format for date
for(JSprint sprint in getAllOpenSprints()) {
if (formatDate(sprint.startDate, format) < 2023){
runnerLog("Sprint name: " + sprint.name);
runnerLog("Sprint id: " + sprint.id);
runnerLog("Sprint start date: " +formatDate(sprint.startDate, format));
}
}

This will give you all Open Sprints before 2023, but if you mean not a calendar year but a year since now (today - 365 days) it needs some adjustments.

Please let me know if that works for you.
Anna

Bhargavi Vasa
Contributor
March 10, 2023

Yeah it's working fine but can we get only the active sprints(i.e., sprint started) which are created 90 days before and get the open issues which are linked to that sprint and change the issue status to close and then close the sprints.

Can you please help on this scenario 

Anna Hryhoruk _Appfire_
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 13, 2023

Hi @Bhargavi Vasa This one should work for the described use case:

string format = "MM/dd/yyyy"; //format for date
string creationdate = currentDate()-"90d";
runnerLog("creation date: " + creationdate);
for(JSprint sprint in getAllOpenSprints()) {
if (sprint.startDate < creationdate and sprint.state =="ACTIVE") {
runnerLog("Sprint name: " + sprint.name);
runnerLog("Sprint id: " + sprint.id);
runnerLog("Sprint start date: " +formatDate(sprint.startDate, format));
runnerLog("Sprint state: " +sprint.state);
string [] keys =selectIssues("Sprint = '" +sprint.name+ "'");
runnerLog("issues " +keys);
for(string key in keys) {
autotransition("Done", key);
}
updateSprint(sprint.id, sprint.name, "Closed" );
runnerLog("Sprint was updated: " + sprint.name );
}
}

 Please let me know how it goes. 
Anna

Bhargavi Vasa
Contributor
March 13, 2023

Hi @Anna Hryhoruk _Appfire_  Thanks for your code

This code is giving the output of all the issues even if they are closed and if they are not part of active sprints,getting all the issues from other sprints as well.

Iam looking for this below use case: 

Scenario 1: Get all active/open sprints created before 3 months ago

Scenario 2: Get the issues which are not closed for "scenario 1"

Scenario 3: Close the issues which we got for "scenario 2"

Scenario 4: Close/Delete the Sprints for "scenario 1"

Anna Hryhoruk _Appfire_
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 13, 2023

It should give you all issue keys associated with sprints listed by : 

runnerLog("Sprint name: " + sprint.name);

Based on the example I provided, I think you can easily modify it to give only issues in a specific state. Routine selectIssues uses just JQL as a parameter, you can read more about it here:  https://appfire.atlassian.net/wiki/spaces/PSJ/pages/15487412/selectIssues

So just modify jql in line 

string [] keys =selectIssues("Sprint = '" +sprint.name+ "'");

 and add state jql condition which suits your use case. 

If you need additional help, please feel free to submit support request here 

Bhargavi Vasa
Contributor
March 14, 2023
string format = "MM/dd/yyyy"; //format for date
string creationdate = currentDate()-"90d";
runnerLog("creation date: " + creationdate);
for(JSprint sprint in getAllOpenSprints()) {
if (sprint.startDate < creationdate and sprint.state =="ACTIVE") {
runnerLog("Sprint name: " + sprint.name);
runnerLog("Sprint id: " + sprint.id);
runnerLog("Sprint start date: " +formatDate(sprint.startDate, format));
runnerLog("Sprint state: " +sprint.state);
string [] keys =selectIssues("Sprint = '" +sprint.name+ "'" and status not in Closed);
runnerLog("issues " +keys);
for(string key in keys) {
autotransition("Done", key);
}
updateSprint(sprint.id, sprint.name, "Closed" );
runnerLog("Sprint was updated: " + sprint.name );
}
}

I have tried this code by giving jql,but it is throwing error
Anna Hryhoruk _Appfire_
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 14, 2023

Try the following syntax: 

 string [] keys =selectIssues("Sprint = '" +sprint.name+ "'" + "and status != 'Closed' ");

or

 string [] keys =selectIssues("Sprint = '" +sprint.name+ "'" + "and status != 'Done' "); 
Bhargavi Vasa
Contributor
March 15, 2023

string format = "MM/dd/yyyy"; //format for date

string creationdate = currentDate()-"90d";

runnerLog("creation date: +creationdate);

for (JSprint sprint in getAllOpenSprints()){

if(formatDate(sprint.startDate, format) < creationdate and sprint.state == "ACTIVE"){ runnerLog("Sprint name: "+sprint.name);

runnerLog("Sprint id: "+sprint.id);

runnerLog("Sprint start date: "+formatDate(sprint.startDate, format));

runnerLog("Sprint state: "+sprint.state);

string jql;

jql=("Sprint=' "+sprint.name+" ' " + "and status="Closed" ' ");

string [] keys = select Issues (jql);

runnerLog("issues " +keys);

for(string key in keys) {

updateSprint (sprint.id, sprint.name, "Closed");

runnerLog("Sprint was updated: +sprint.name);

 

This is the exact code I was running but unable to get the issues on the date given for above script, getting all the issues which are not part of those open sprints which has sprint starting date created before 90days.

Here I need to get the sprints created before an year ago which is having only the closed issues to close the Sprint 

This is the logic I required for the code:

If sprint is open which has been created before 90 days ago and if the issues under that sprints are "open", close loop(avoid open issues) and in other loop get all the issues part of that sprints which were "closed"  and close the sprint.

Suggest an answer

Log in or Sign up to answer