Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Update endtime by adding Hours from custom_field to the starttime(Custom_field)

Salil Sekhar July 29, 2024

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 


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

 

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')}}" } } } }

1 answer

1 accepted

0 votes
Answer accepted
Bill Sheboy
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 29, 2024

Hi @Salil Sekhar -- 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

Salil Sekhar July 29, 2024

@bill  : 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. 

Salil Sekhar July 29, 2024

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

Salil Sekhar July 29, 2024

this is how the metadata looks like for both customfields2024-07-29_21-02-47.png.

2024-07-29_21-00-09.png

 

Bill Sheboy
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 29, 2024

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: {{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)}}

 

Salil Sekhar July 29, 2024

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

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"

Bill Sheboy
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 29, 2024

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

 

Salil Sekhar July 29, 2024

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.

Bill Sheboy
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 29, 2024

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.

Like Salil Sekhar likes this
Salil Sekhar July 29, 2024

2024-07-29_22-47-16.png

Coming as blank

Bill Sheboy
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 29, 2024

Thanks...Now adjust that last one to convert the text to a number:

{{issue.customfield_10590.plusHours(issue.customfield_10592.value.asNumber)}}
Salil Sekhar July 29, 2024

2024-07-29_22-58-46.png

got updated this time.

Like Bill Sheboy likes this
Salil Sekhar July 29, 2024

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"


you are a rock star @Bill Sheboy 👍👌 

Like Bill Sheboy likes this
Bill Sheboy
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 29, 2024

Awesome; I am glad we got it working!

Like Salil Sekhar likes this

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
PREMIUM
TAGS
AUG Leaders

Atlassian Community Events