I want to set due date based on SLA "due".
IF I create new ticket SLA's due day is two days,
it is possible using "sla's due day" to set "system field due date" with scriptrunner?
Hi @Eric.LA_Chen
This is almost impossible to achieve because you have rules that pause the timer. Also you have to have in count the calendars in the SLA.
Besides that here you have the code to put the first "Due Date" for the SLA given.
import com.atlassian.jira.component.ComponentAccessorimport com.atlassian.jira.issue.ModifiedValueimport com.atlassian.jira.issue.fields.CustomFieldimport com.atlassian.jira.issue.util.DefaultIssueChangeHolderimport com.atlassian.jira.user.UserUtilsimport com.atlassian.servicedesk.api.sla.info.SlaInformationimport com.atlassian.servicedesk.api.sla.info.SlaInformationQueryimport com.atlassian.servicedesk.api.sla.info.SlaInformationServiceimport com.atlassian.servicedesk.api.util.paging.PagedResponseimport com.atlassian.servicedesk.api.util.paging.SimplePagedRequestimport com.onresolve.scriptrunner.runner.customisers.WithPluginimport java.sql.Timestamp@WithPlugin("com.atlassian.servicedesk")SlaInformationService slaInformationService = ComponentAccessor.getOSGiComponentInstanceOfType(SlaInformationService)CustomField cfDueDate = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectsByName("Due Date").first() //Change with your "Due Date" CF NameSlaInformationQuery query = slaInformationService.newInfoQueryBuilder() .issue(issue.getId()) .pagedRequest(SimplePagedRequest.paged(0, 5)) .build()PagedResponse<SlaInformation> pagedResponse = slaInformationService.getInfo(UserUtils.getUser("admin"), query) //Change with your admin userstatic SlaInformation getSlaInformation(PagedResponse<SlaInformation> pagedResponse, String slaName) { SlaInformation slaInformation = pagedResponse.getResults()?.find { it.getName() == slaName} return slaInformation ? slaInformation : null}static Timestamp getSlaDueDate(SlaInformation slaInformation) { Timestamp dateif (slaInformation) { slaInformation.getOngoingCycle().ifPresent({ it.getBreachTime().ifPresent({ date = Timestamp.from(it) } )} ) }return date ? date : null}cfDueDate.updateValue(null, issue,new ModifiedValue( issue.getCustomFieldValue(cfDueDate),getSlaDueDate(getSlaInformation(pagedResponse, "Tiempo hasta primera respuesta"))) //Change with your SLA Name ,new DefaultIssueChangeHolder())
You can put it in the create postfunction (in the last position).
Also you could write a listener or maybe a Script Field to maintain it updated.
Regards!
Hi Eric,
You can call this REST endpoint from your script to get SLA information for your issue.
It looks like you're new here. Sign in or register to get started.