Missed Team ’24? Catch up on announcements here.

×
Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Clear the SLA on Sub-Task creation using ScriptRunner

Yasir Bashir January 27, 2016

We use ScriptRunner to create Sub-tasks. All the fields from the Parent task are copied over to the Sub-Task. All the Sub-tasks are handled by another team and display the SLAs of parent ticket is causing confusion. Is it possible to clear the SLA on the sub-task when it gets created using Additional Issue Actions?

1 answer

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

0 votes
Kristian Walker _Adaptavist_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
January 29, 2016

Hi Yashir,

It is not possible to clear the issue actions using Service Desk for the SLA Fields due to the fact the SLA fields store multiple values in them.

If you run the code below in the Script Console then you will see what an SLA value looks like.

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue;

// Enter the Key of a Service Desk Issue here.
Issue subIssue = ComponentAccessor.getIssueManager().getIssueObject("KDSD-39")

def customFieldManager = ComponentAccessor.getCustomFieldManager()
def timeToSlaField = customFieldManager.getCustomFieldObjectByName("Time to first response");

// Show the value held for that field in the database.
return timeToSlaField.getValue(subIssue).toString()

One workaround would be to create a custom script post function below the Script Condition that create the sub task on the transition and add code in similar to below to remove the SLA field on the subtask. Note - This example code will need refactoring so you don't clear the SLA value on the parent task as it currently clears the value on the parent task as well.

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.MutableIssue

// Get the required Managers
def customFieldManager = ComponentAccessor.getCustomFieldManager()

// Get the SLA Custom Fields
def timeToResolution = customFieldManager.getCustomFieldObjectByName("Time to resolution");
def timeToFirstResponse = customFieldManager.getCustomFieldObjectByName("Time to first response");


// Construct the key of the next Subtask
def currentIssue = issue.toString()
// Extract the project key from the issue
def projectKey = currentIssue.replaceAll("[^A-Z]","").toString();
// Get the Issue Number as an integer
def CurrentIssueNumber = currentIssue.replaceAll("[^1-9]","").toInteger();
// Increment th issue number by 1
def SubTaskIssueNumber  = CurrentIssueNumber + 1
// Constrcut the Issue Key of the next SubTask
def subTaskKey =  projectKey + "-" + SubTaskIssueNumber

// Construct a pointer to the subtask issue object
MutableIssue subIssue = ComponentAccessor.getIssueManager().getIssueObject(subTaskKey)

if (subIssue) {

    // Clear the SLA Fields
    timeToResolution.remove()
    timeToFirstResponse.remove()

}

 

I hope this helps.

Kristian

TAGS
AUG Leaders

Atlassian Community Events