Update endtime by adding Hours from custom_field to the starttime(Custom_field)
Asked by Salil Sekhar:

EndTime : {{#=}}({{issue.customfield_10590.convertToTimeZone('UTC').toMillis}} +(({{issue.customfield_10592}} + 1) \* 3600 \* 1000)).toDate{{/}}

issue.customfield_10590 : is the start time in datetime format

issue.customfield_10592 : is the hours in string/number format that I want to pass as an end time in a post web request call for a third-party integration.  

right now when I am passing Endtime as a custom variable to the main custom body I am getting this error   

<br />

Your outgoing web request configuration is invalid. Please fix the following errors and try again. Invalid smart value expression in custom body, please see smart values in our documentation for help with syntax.

please help me on this one.

![2024-07-29_13-50-56.png](/t5/image/serverpage/image-id/338469iBEE76958E969FDBA/image-size/large?v=v2&px=999 "2024-07-29_13-50-56.png")

Full Custom Body  

{ "data": { "type": "downtime", "attributes": { "scope": "\*", "monitor_identifier": { "monitor_tags": \["\*\*\*\*\*\*"\] }, "display_timezone": "Asia/Kolkata", "message": "Message about the downtime", "mute_first_recovery_notification": false, "notify_end_states": \[ "alert", "warn" \], "notify_end_types": \[ "canceled", "expired" \], "schedule": { "end": "{{EndTime}}", "start": "{{issue.customfield_10590.convertToTimeZone('UTC')}}" } } } }


Answers:
author: Bill Sheboy
body: Hi [@Salil Sekhar](/t5/user/viewprofilepage/user-id/5067868) -- Welcome to the Atlassian Community!

What does your customfield_10592 contain? Is it:

1. a number of hours with which to increment the start time,
2. a representation of the time of day (e.g., 2pm or 1400) with which to set for the start time, or
3. something else?

If it is the first one, please try using one of the *plus* functions to increment the start date: <https://support.atlassian.com/cloud-automation/docs/jira-smart-values-date-and-time/#Date-plus-unit--->

If it is the second one, please try using one of the *with* functions to set the time of day: <https://support.atlassian.com/cloud-automation/docs/jira-smart-values-date-and-time/#Date-with-attribute--->

If it is something else, please clarify what problem you are trying to solve. Thanks!

Kind regards,  
Bill

comments: author: Salil Sekhar
body: [@bill](/t5/user/viewprofilepage/user-id/5462438) : thanks for the reply, the customfield_10592 is of type "options: and is basically telling the exact hours by which we have to create an end time example: if the startTime (customfield_10590) is on DEC 19 2022 11:00 PM, the endTime should be at 6 hours + 1 hour (by default) DEC 20 2022 6:00 AM.


author: Salil Sekhar
body: i need to add the value present under customfield_10592 as an hour in the datetime and make it an end time.


author: Salil Sekhar
body: this is how the metadata looks like for both customfields![2024-07-29_21-02-47.png](https://community.atlassian.com/t5/image/serverpage/image-id/338585i76F0EFA318244023/image-size/large?v=v2&px=999 "2024-07-29_21-02-47.png").

**![2024-07-29_21-00-09.png](https://community.atlassian.com/t5/image/serverpage/image-id/338583i15D0D06BAAF09324/image-size/large?v=v2&px=999 "2024-07-29_21-00-09.png")**


author: Bill Sheboy
body: To use the values of the select option field in a rule, it is accessed with the *value* attribute: {{issue.customfield_10592.value}}

That is a text value. As you want to use that as a number, add a [conversion](https://support.atlassian.com/cloud-automation/docs/jira-smart-values-text-fields/#asNumber): {{issue.customfield_10592.value.asNumber}}

However, I am still confused by the example you provided...

Do you want to add the hour value:

{{issue.customfield_10590.convertToTimeZone("UTC").plusHours(issue.customfield_10592.value.asNumber)}}

Or set the time attribute to that hour:

{{issue.customfield_10590.convertToTimeZone("UTC").withHour(issue.customfield_10592.value.asNumber)}}


author: Salil Sekhar
body: Start time (customfield_10590) : 2022-12-19T09:30:00.000-0800

NAVSRO - Maintenance Window Duration (Hours) (customfield_10592) : "6"

End Time : {{issue.customfield_10590.convertToTimeZone("UTC").plusHours(issue.customfield_10592.value)}} i.e. 2022-12-19T15:30:00.000-0800  

This is what I want.  

but I have tried this one out what you have pasted.  

it gives me an error:  

![2024-07-29_22-13-31.png](https://community.atlassian.com/t5/image/serverpage/image-id/338607i4EE443B394718001/image-size/large?v=v2&px=999 "2024-07-29_22-13-31.png")

this is how I am trying to run it , "start" is perfectly getting picked but not the "end"  

"end": "{{issue.customfield_10590.plusHours(issue.customfield_10592.value)}}+00:00",  
"start": "{{ issue.customfield_10590.format("yyyy-MM-dd'T'HH:mm:ss") }}+00:00"

This is the exact format in which I want the dateime in the body :

**"2024-08-17T16:00:00+00:00"**


author: Bill Sheboy
body: I recommend adding the hours to the start date / time, and then using the built-in or the format() function to set the value rather than trying to concatenate the text:

<https://support.atlassian.com/cloud-automation/docs/jira-smart-values-date-and-time/#Date-format--->


author: Salil Sekhar
body: already tried this one as well, but that didn't work:

"start": "{{issue.customfield_10590.format("yyyy-MM-dd'T'HH:mm:ssZ")}}"

also I tried jiraDateTime but even that's not supported as it's coming like this :  
"start": "2024-04-17T16:00:00+0000" which Is not supported.  


author: Bill Sheboy
body: Please try writing these to the audit log to see if they match what you expect:

```
start date / time: {{issue.customfield_10590}}

value to add: {{issue.customfield_10592.value}}

incremented date / time: {{issue.customfield_10590.plusHours(issue.customfield_10592.value)}}

```

After you confirm the math is working, then you can focus on the formatting.


author: Salil Sekhar
body: ![2024-07-29_22-47-16.png](https://community.atlassian.com/t5/image/serverpage/image-id/338620iB894639DF5A47C08/image-size/large?v=v2&px=999 "2024-07-29_22-47-16.png")

Coming as blank


author: Bill Sheboy
body: Thanks...Now adjust that last one to convert the text to a number:

```
{{issue.customfield_10590.plusHours(issue.customfield_10592.value.asNumber)}}
```


author: Salil Sekhar
body: ![2024-07-29_22-58-46.png](https://community.atlassian.com/t5/image/serverpage/image-id/338627i3A129382C3F5162E/image-size/large?v=v2&px=999 "2024-07-29_22-58-46.png")

got updated this time.


author: Salil Sekhar
body: **This was quick! ?**

Final working piece :   
**"end": "{{issue.customfield_10590.plusHours(issue.customfield_10592.value.asNumber).plusHours(1).format("yyyy-MM-dd'T'HH:mm:ss")}}+00:00",**   
"start": "{{ issue.customfield_10590.format("yyyy-MM-dd'T'HH:mm:ss") }}+00:00"

<br />

you are a rock star [@Bill Sheboy](/t5/user/viewprofilepage/user-id/1685313) ??


author: Bill Sheboy
body: Awesome; I am glad we got it working!


Tags: cloud

datadog

jira-automation

jira-cloud