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

Next challenges

Recent achievements

  • Global
  • Personal

Recognition

  • Give kudos
  • Received
  • Given

Leaderboard

  • Global

Trophy case

Kudos (beta program)

Kudos logo

You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.

View group

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

Get sla value

HI,

I wont to copy sla due into scripted custom field, how i can do it?

1 answer

Hi Taras,

What data from the SLA do you want in the script field? The following set-up will allow you to see what is available by using the preview functionality, but ultimately you'll need to write a velocity template to display the information you want to see.

  • Note: whatever you want, can be left blank
  • Template: Custom
  • Custom Template: $value
  • Inline script
    import com.atlassian.jira.component.ComponentAccessor
    import com.atlassian.jira.issue.CustomFieldManager
    import com.atlassian.jira.issue.Issue
    import com.atlassian.jira.issue.fields.CustomField

    Issue issue = issue
    CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager()
    CustomField cf = customFieldManager.getCustomFieldObjectByName("NAME OF SLA FIELD")
    def value = issue.getCustomFieldValue(cf)
    return value
    (N.B. 'NAME OF SLA FIELD' should be replaced with the name of the field that contains the SLA of interest.)
  • Preview Issue Key: The key of a Service Desk issue that has the appropriate SLA field.

When you click the 'Preview' button, you should see something similar to this in the 'Result' tab:

SLAValue{completeSLAData=[], timeline=Timeline{events=[TimelineEvent{date=2017-12-20T13:55:35.871Z, types=[START]}]}, ongoingSLAData=OngoingSLAData{goalId=1, startTime=2017-12-20T13:55:35.871Z, paused=false, thresholdData=some(ThresholdData{calculatedAt=2017-12-20T15:25:36.182Z, remainingTime=some(8999689), thresholdsConfigChangeDate=2017-12-20T13:55:35.048Z, thresholdsConfigChangeMsEpoch=1513778135048})}, metricId=1, definitionChangeDate=1970-01-01T00:00:00.000Z, definitionChangeMsEpoch=0, goalsChangeDate=2017-12-20T13:55:35.139Z, goalsChangeMsEpoch=1513778135139, goalTimeUpdatedDate=2017-12-20T13:55:35.128Z, goalTimeUpdatedMsEpoch=1513778135128, metricCreatedDate=1513778135048, updatedDate=some(1513783536245)}

If you were to use the above script field configuration as-is, this is pretty much what the contents of the field would look like in the UI, which is probably not what you want. However, it does at least show you what data you can access and how it's structured. For example, you could get the datetime of the first timeline event by using the following Custom Template:

$value.timeline.events.get(0).date

Which would give a result of "2017-12-20T13:55:35.871Z".

Hope this gives you some pointers in the right direction.

Yours,

Jake

Hi

Thanks for this solution. It works with this date from 'timeline' field.

Can You give me some clues how to get

remainingTime

value, from SLAValue -> ongoingSLAData -> thresholdData?

I tried something like this below... with many variations

$value.ongoingSLAData.get(0).thersholdData.get(0).remainingTime

but with no success.

Finally managed to get it after printing SLAValue obj to String :)

But still trying to get may value 'remainingTime' more elegant way :)

Hi Karol,

It looks like the following template should work, although bear in mind that it doesn't do any null checking so it might produce errors if the expected properties are not present:

$value.ongoingSLAData.thresholdData.get().remainingTime.get()

Perhaps the better option would be to incorporate the above expression into the script itself and just use $value in the template:

//...rest of script
def value = issue.getCustomFieldValue(cf)
return valuevalue.ongoingSLAData.thresholdData.getOrNull()?.remainingTime?.getOrNull()

This also makes the field null-safe.

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Marketplace Apps & Integrations

Do Not Lose your Customer’s Trust

Missing deadlines is one of the biggest problems every team lead wants to avoid when dealing with managed services. When the customer contracts your company to help with IT services it is expected th...

24 views 0 0
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