Hi there,
Consider the following, a ticket is created with the following string in the summary:
"Put server in Maintenance mode for FC1.2 Deployment at 13:30:00 GMT-0500 (Mountain Daylight Time) on Thu Jun 29 2023"
Each time a ticket is created, the section "Put server in Maintenance mode" is consistent, while "FC1.2" changes, the time "13:30:00 GMT-0500" changes, as well as the date.
What I'm looking to do is extract the time "13:30:00" and replace it in the Summary with a time 30 minutes prior (e.g. "13:00:00")
I have an automation rule that is triggered when this issue type is created and using regex to match the string using (which passes)
{{issue.summary}}
contains regular expression
((Put server in Maintenance mode for .* at )\d{2}:\d{2}:\d{2})
Next I use the Edit Issue action to update the time in Summary using the following:
{{issue.summary.replaceAll("(?<=Put server in Maintenance mode for .* at )\d{2}:\d{2}:\d{2}", {{now.minusMinutes(30).format("HH:mm:ss")}})}}
But I keep getting the error "Error rendering smart-values when executing this rule:"
Any idea how (or if) I can update the Summary using this combination of regex, smart values and smart functions?
Thanks!
Jason
I figured out how to do this, just putting here for anyone else looking to do the same.
Ticket is created w/template summary (brackets indicate changing values):
"Put server in Maintenance mode for [v1.2] Deployment at [13:30:00] [GMT-0500] ([Mountain] Daylight Time) on [Thu Jun 29 2023]"
First conditional check to see if the summary matches this string:
{{issue.summary}}
contains regular expression
((Put server in Maintenance mode for .* at )\d{2}:\d{2}:\d{2})
Then pull the time "13:30:00" as string from the summary & assigned variable {{currentTime}}
{{issue.summary.match(".*(\b\d{2}:\d{2}:\d{2}\b).*")}}
To convert the {{currentTime}} string to a date object, created another variable {{newTime}} using a dummy random date:
2023-01-01T{{currentTime}}+0000
Used the {{newTime}} date object variable with minusMinutes function to change the time in Summary to 30 minutes for Create Issue action. The rest of the original Summary is concatenated before and after {{newTime}}
{{summary.match("(Put server in Maintenance mode for .* at)")}} {{newTime.toDate.minusMinutes(30).as("HH:mm:ss")}}{{summary.match("( GMT-0600.*| GMT-0500.*)")}}
Thanks for your replies!
Hi @Jason M_ -
I'm curious what the point of "?<=" is at the beginning of your regex. My usual regex tester did not recognize it.
But as to the replacement, I think the problems is that you actually need a lot less braces:
{{issue.summary.replaceAll("(Put server in Maintenance mode for .* at )\d{2}:\d{2}:\d{2}", now.minusMinutes(30).format("HH:mm:ss"))}}
However the problem now is that you'll be missing everything preceding the time, which you normally would use $1 for, except I don't believe you can mix that with the now Smart Value.
SO, to get that text back, you can use a match, which is kinda nasty but enh, it worked:
{{issue.summary.match("(Put server in Maintenance mode for .* at )")}}{{issue.summary.replaceAll("(Put server in Maintenance mode for .* at )\d{2}:\d{2}:\d{2}", now.minusMinutes(30).format("HH:mm:ss"))}}
(That is all on one line.)
OH, you will probably need to adjust that for your time zone. So then:
{{issue.summary.match("(Put server in Maintenance mode for .* at )")}}{{issue.summary.replaceAll("(Put server in Maintenance mode for .* at )\d{2}:\d{2}:\d{2}", now.minusMinutes(30).convertToTimeZone("MST7MDT").format("HH:mm:ss"))}}
Minor nitpick, MDT is -0600, I think.
I tested this just now, logging the value to the Audit Log as well as plopping that whole mess into an Edit issue fields block to modify the Summary field.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
BTW, I'm sure you already know this, but for anyone coming afterwards, here's some reference docs to help you "decode" the aforementioned smart values.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Darryl,
Thank you much for your analysis and reply, I did try this approach but no dice.
At this point I am getting some success by concatenating the summary in the following way:
Edit issue action:
{{summary.match("(.* at)")}} {{updatedTime}} {{summary.match("(:00.*)")}}
I've successfully extracted the "13:30" from original summary (as described above) into a variable {{currentTime}}, but right now stuck on converting the "13:30" into a dateTime object so I can use a time function on it (minusMinutes(30)) and assign to variable {{updatedTime}}.
The following is not working, as trying to log {{updatedTime}} always comes up empty. Any suggestions?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
AH, I did not know you were trying to modify the time captured from the summary, as in your original post you were using {{now.minusMinutes(30).format("HH:mm:ss")}}.
Glad you figured it out.
In your final solution, does {{summary.match...}} work or did you mean to write {{issue.summary...}?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Indeed that was a mistake on my part referencing {{now}}.
So it turns out either {{issue.summary.match...}} or {{summary.match...}} both work. This is our Sandbox environment tho, to be safe for production I updated all to be issue.summary...good catch, thanks for the help!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I wonder about the capabilities of replaceAll to manage different sets of double-quotes.
What happens if you create a variable like {{nowMinus30Minutes}} to break out this part of the calculation?
{{now.minusMinutes(30).format("HH:mm:ss")}}
Then have this instead?
{{issue.summary.replaceAll("(?<=Put server in Maintenance mode for .* at )\d{2}:\d{2}:\d{2}", {{nowMinus30Minutes}})}}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks Erin! While there was no change doing this w/original syntax, this got me re-thinking the approach and was able to resolve.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.