Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Deleted user
0 / 0 points
Next:
badges earned

Your Points Tracker
Challenges
Leaderboard
  • Global
  • Feed

Badge for your thoughts?

You're enrolled in our new beta rewards program. Join our group to get the inside scoop and share your feedback.

Join group
Recognition
Give the gift of kudos
You have 0 kudos available to give
Who do you want to recognize?
Why do you want to recognize them?
Kudos
Great job appreciating your peers!
Check back soon to give more kudos.

Past Kudos Given
No kudos given
You haven't given any kudos yet. Share the love above and you'll see it here.

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

HOW do I get SLA value with scriptrunner

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?

 

螢幕快照 2019-11-05 下午16.14.55 下午.png

2 answers

Hi Eric,

You can call this REST endpoint from your script to get SLA information for your issue.

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.ComponentAccessor
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.jira.user.UserUtils
import com.atlassian.servicedesk.api.sla.info.SlaInformation
import com.atlassian.servicedesk.api.sla.info.SlaInformationQuery
import com.atlassian.servicedesk.api.sla.info.SlaInformationService
import com.atlassian.servicedesk.api.util.paging.PagedResponse
import com.atlassian.servicedesk.api.util.paging.SimplePagedRequest
import com.onresolve.scriptrunner.runner.customisers.WithPlugin

import 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 Name

SlaInformationQuery 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 user

static 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 date
if (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!

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase

The benefits of using Jira in different departments

Jira is a great tool to use across different departments. Forget that paperwork – switch to Jira and get that tasks done smoothly. Marketing Jira allows for a complete digital transformation of you...

97 views 0 5
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you