Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,367,221
Community Members
 
Community Events
168
Community Groups

Start date and due date coming from Sprint

if a Sprint value is added/updated to a User story on either Create/Edit screen,

then the start date and due date fields for that US should be updated with the start and end date of the assigned Sprint

Any thoughts on this? 

2 answers

2 accepted

2 votes
Answer accepted

Hi Mihai,

I wrote this script some years back and could be useful to you. This goes to the Behaviours part of the ScriptRunner plugin in JIRA and someone good with java date/time libs can perhaps optimize it. Also a part of this I found it online, so credit to those too.

Hope this helps!

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.onresolve.jira.groovy.user.FormField
import com.onresolve.jira.groovy.user.FieldBehaviours
import groovy.transform.BaseScript
import static com.atlassian.jira.issue.IssueFieldConstants.*
import com.atlassian.greenhopper.service.sprint.SprintManager
import com.onresolve.scriptrunner.runner.customisers.JiraAgileBean
import com.onresolve.scriptrunner.runner.customisers.WithPlugin
import com.atlassian.greenhopper.service.sprint.Sprint
//import java.sql.Timestamp
//import java.text.SimpleDateFormat;
//import java.util.Date;
//import java.time.format.DateTimeFormatter
//import java.text.SimpleDateFormat
//import java.time.LocalDate
import org.joda.time.DateTime

import com.onresolve.scriptrunner.runner.customisers.PluginModuleCompilationCustomiser

//@BaseScript FieldBehaviours fieldBehaviours
@WithPlugin("com.pyxis.greenhopper.jira")
@JiraAgileBean
SprintManager sprintManager

List<String> ListProjectNotToInclude = ["GRICCO","SWT154","MKIV","EM","MK2R19","MKVING11","NG9","MK2","WIPS","AF","DSA","EDT07","NG9EM"]

if (!ListProjectNotToInclude.contains(issueContext.projectObject.key))
{

  def sprintFormField = getFieldByName("Sprint")

   if(sprintFormField.value) //if(sprint && sprint.state == "ACTIVE"){

    {
        Long sprintVal = sprintFormField.value as Long
        def sprintManager1 = PluginModuleCompilationCustomiser.getGreenHopperBean(SprintManager)
DateTime dtStartdate = sprintManager1.getSprint(sprintFormField.value as Long)?.getValue()?.getStartDate()
        DateTime dtEnddate = sprintManager1.getSprint(sprintFormField.value as Long)?.getValue()?.getEndDate()
     

        if (dtStartdate && dtEnddate)
        {
            def customField1 = customFieldManager.getCustomFieldObject("customfield_20506") // Start date
            def customField2 = customFieldManager.getCustomFieldObject("customfield_20507") // End date
            int intDay1 = dtStartdate.getDayOfMonth()
            int intYear1 = dtStartdate.getYear()
            int intMonth1 = dtStartdate.getMonthOfYear()

            String strMonthPart1 = ""
            if (intMonth1 == 1)

                strMonthPart1 = "Jan"

            else if (intMonth1 == 2)

                strMonthPart1 = "Feb"

            else if (intMonth1 == 3)

                 strMonthPart1 = "Mar"

             else if (intMonth1 == 4)

                 strMonthPart1 = "Apr"

             else if (intMonth1 == 5)

                 strMonthPart1 = "May"

             else if (intMonth1 == 6)

                 strMonthPart1 = "Jun"

             else if (intMonth1 == 7)

                 strMonthPart1 = "Jul"

             else if (intMonth1 == 8)

                 strMonthPart1 = "Aug"

             else if (intMonth1 == 9)

                 strMonthPart1 = "Sep"

             else if (intMonth1 == 10)

                 strMonthPart1 = "Oct"

             else if (intMonth1 == 11)

                 strMonthPart1 = "Nov"

             else if (intMonth1 == 12)

                 strMonthPart1 = "Dec"

             getFieldById("customfield_20506").setFormValue(intDay1 + "/" + strMonthPart1 + "/" + intYear1) // Start date

             //getFieldById("customfield_20506").setFormValue("1/Jan/2019")

             int intDay2 = dtEnddate.getDayOfMonth()

             int intYear2 = dtEnddate.getYear()

             int intMonth2 = dtEnddate.getMonthOfYear()

             String strMonthPart2 = ""

             if (intMonth2 == 1)

                 strMonthPart2 = "Jan"

             else if (intMonth2 == 2)

                 strMonthPart2 = "Feb"

             else if (intMonth2 == 3)

                 strMonthPart2 = "Mar"

             else if (intMonth2 == 4)

                 strMonthPart2 = "Apr"

             else if (intMonth2 == 5)

                 strMonthPart2 = "May"

             else if (intMonth2 == 6)

                 strMonthPart2 = "Jun"

             else if (intMonth2 == 7)

                 strMonthPart2 = "Jul"

             else if (intMonth2 == 8)

                 strMonthPart2 = "Aug"

             else if (intMonth2 == 9)

                 strMonthPart2 = "Sep"

             else if (intMonth2 == 10)

                 strMonthPart2 = "Oct"

             else if (intMonth2 == 11)

                 strMonthPart2 = "Nov"

             else if (intMonth2 == 12)

                 strMonthPart2 = "Dec"

             getFieldById("customfield_20507").setFormValue(intDay2 + "/" + strMonthPart2 + "/" + intYear2)

        }

        else

        {

            getFieldById("customfield_20506").setFormValue("") // Start date

            getFieldById("customfield_20507").setFormValue("")

            return

        }

    }

  else

  {

        getFieldById("customfield_20506").setFormValue("") // Start date

        getFieldById("customfield_20507").setFormValue("")

     return

  }

}    
1 vote
Answer accepted
Elvir Rising Star Sep 06, 2022

Hello Mihai,

 

I think I understand where you wanna go there but in real life, all user stories do not start and end during the same time frame within the same sprint. Some user stories might get started in the middle of the sprint, and some not even finished.

I guess you would like to reach for consistency in these dates, and not update them manually.

By the way, you can get the sprint dates in the sprint reports, and from there all the related user stories.

 

Best regards,

Hi Elvir, Thank for taking the time! You are right, I just wanted them to be visible on the Plans board, and due to missing start and end date the US cannot be visualized :) 

Elvir Rising Star Sep 06, 2022

Oh I see,

 

In Plan, dates are automatically taken from the sprint start and end date if the these fields are empty.

I am in Jira cloud and this is what I get

image.png

 

Please check your Plan configuration

image.png

 

Best regards,

Elvir, that fixed it!!!! You amazing man!

Elvir Rising Star Sep 06, 2022

You are amazing too, please accept my answer.

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
STANDARD
TAGS

Atlassian Community Events