JMWE set issue field from another field (SLA calculation)
Asked by Jennifer Marple:

Hi - I'm working on migrating many native JSM automations (which were configured by a predecessor of mine - so I don't always have the context) into JMWE. I have one still relatively high use rule that I haven't yet figured out how to properly configure in JMWE.

The automation appears relatively simple. It's running hourly, and editing an issue field called "Response SLA Time". That field appears to be just a calculation of how long it took to make first response on an issue (but it factors in whatever SLA rules are configured, to discount weekends/off work hours, etc).  

The native JSM automation just has this as the value to set:

{{time to first response.completedCycles.elapsedTime.friendly}}

The field "time to first response" is a count down, showing how much time remains on the SLA. So, say the priority/project/organization on the issue warrants an 8 hour SLA, this value starts at 8, and goes down to 0 and then into the negatives if the SLA is exceeded (also that count down pauses whenever outside of the defined business hours as applicable per SLA).

The field "Response SLA Time" is calculating the inverse of that time to first response. So for instance, if "time to first response" is 7:50, that means the case was responded to in 10 minutes, and the old automation would populate "Response SLA Time" with "10m".

This new value is in turn being used in some reports and fed to extracts that populate some dashboards and other visualizations about SLA attainment and such.

How do I translate:

{{time to first response.completedCycles.elapsedTime.friendly}}

into something JMWE can use in the Set Issue Fields post function for the field "Response SLA Time"?


Answers:
author: David Fischer
body: Hi [@Jennifer Marple](/t5/user/viewprofilepage/user-id/5423895)

have you tried this?

```
{{issue.fields["time to first response"].completedCycles.elapsedTime.friendly}}
```

comments: author: Jennifer Marple
body: I hadn't, but tried it now.

It runs, and appears in the JMWE logs as INFO status, no failures noted, but doesn't appear to perform the expected update.

I have an "If Scope" Target issues JQL set in the JMWE Event-based action like this:

```
project = "The Actual Project in Question" AND "Response SLA time[Short text]" IS EMPTY AND reporter in (myself)
```

I tested that JQL in a filter separately, and the issue I'm using to test does come up as expected.


author: David Fischer
body: Can you just "Test" the script using the "Test Nunjucks template" button while editing your event-based action against an issue that has a value for that "time to first response" SLA field?


author: Jennifer Marple
body: Did try that, it responds just with: Your template ran successfully

(no True or False as I've seen when testing other scripts)


author: David Fischer
body: Sorry, my bad, the syntax is:

```
{{ issue.fields['Time to first response'].completedCycles | last | field('elapsedTime.friendly') }}
```

Make sure you replace "Time to first response" with the exact name (case-sensitive) of the SLA field.


author: Jennifer Marple
body: that looks promising! I got "4m" as my test result this time. Have it scheduled to run in about 5 minutes and we'll see if it catches this test case this time. Assuming so - I'll then remove the boundaries I put to keep it to just my test case.  

Thank you [@David Fischer](/t5/user/viewprofilepage/user-id/538255) !


author: Jennifer Marple
body: Worked as expected on the schedule, thank you!


Tags: addon-com.innovalog.jmwe.jira-misc-workflow-ex

cloud

jira-service-management

jira-service-management-cloud

jmwe