I am trying to recreate the customer notification system by using Automation in our Jira Data Center version 8.20. Among the rules, I want to implement a rule which is: When a request participant is added => Notify the added particpants.
The "send email" action in Jira automation does not have the added participant as a choice for receipients, so I am thinking to work around it with a smart values as follow:
{{#issue.customfield_14061}}
{{# if(equals(accountId, fieldChange.to.replace(fieldChange.from, "").replace(",", "").trim()))}}
{{emailAddress}}
{{/}}
{{/}}
Any idea how the above problem can be solved is greatly appreciated.
Thank you very much!
Ok, if you're somehow going to be able to train/limit your users to only add ONE Request Participant at a time, then you could do this with a Web Request to Jira's Rest API.
You can make a call to this endpoint to "lookup" the email address:
https://YOURSITE/rest/api/2/user?key={{fieldChange.to.replace(fieldChange.from, "").replace(",", "").trim()}}
This returns a response that includes email, which you can access as:
{{webhookResponse.body.emailAddress}}
So I'm roughly following these instructions:
With the difference being that Personal Access Tokens in on-prem Jira are used as Bearer tokens. So the Header is slightly different and requires no base64 encoding.
Hi!
This is a very cool idea to try out, I didn't think of sending the web request at all, that's pretty interesting. But still the question would be how do we get the person who was added?
My formula using
fieldChange.to.replace(fieldChange.from, "").replace(",", "").trim()
will only work if fieldChange.to and fieldChange.from is sorted in the same way and the person who was added is added into the beginning or the end of the list. But in cases that we have:
fieldChange.from = [JIRAUSER1234, JIRAUSER5678]
then JIRAUSER3456 is added
fieldChange.to = [JIRAUSER1234, JIRAUSER3456, JIRAUSER5678]
the replacement now doesn't work any more.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Aw man. We really need to be able to SORT both lists and then DIFF them. Hum.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Oh man @Trang Ngoc Nguyen this is a clever idea! (Check it out, @Bill Sheboy :-)
But I also could not get it to work on Jira Server 8.20.10.
I even added this check for a specific user (via the audit log) , and it came back positive:
Match? {{#if(equals("JIRAUSER10105", fieldChange.to.replace(fieldChange.from, "").replace(",", "").trim()))}}YES!{{/}}
(Using the audit log saves you from having to write the smart value to a field.)
So then, a conditional check against the manipulated {{fieldChange}} value seems to work.
And this test returns the correct email address of my colleague:
Email: {{#issue.customfield_10000}}{{#if(equals(accountId, "JIRAUSER10105"))}}{{emailAddress}}{{/}}{{/}}
So... filtering based on a static value works.
But yeah, combine the two, and I get nothing:
{{#issue.customfield_10000}}{{#if(equals(accountId, fieldChange.to.replace(fieldChange.from, "").replace(",", "").trim()))}}{{emailAddress}}{{/}}{{/}}
That's basically your original rule, removing the space between the # and the if,as well as all extra spaces because I know that at least with Advanced Field Editing, sometimes Automation doesn't like the spaces.
I saw your comment in this old question and yeah, @Sam Harding - any thoughts?
Sidenote: Pretty sure this would break if somebody added multiple Request Participants at the same time, because your {{fieldChange}} value becomes "JIRAUSER20318 JIRAUSER14100" and that's not going to match any single accountId.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
OH. I just realized what the problem might be.
We're trying to use {{fieldChange}} within a {{#issue.customfield_10000}}
So what it's looking for is:
{{issue.customfield_10000.fieldChange.to}}
Which um, yeah, is not valid.
We need to way to reference the "global variable" {{fieldChange}} inside of the iteration of the custom field.
Hum... I vaguely remember there's a way to do this, but am having to Google around... Maybe @Bill Sheboy can answer before I find it. :-}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thank you @Darryl Lee for taking a look! I have seen Bill's explanation of why this doesn't work (as it is not possible referencing to another smart value within interator) and tried follow with his suggestions on these posts:
So I created a custom field that hold the value of the request participant Ids and Email Address using
"{{#issue.customfield_14061}} !!{{accountId}};{{emailAddress}}!! {{/}}"
And another field holding the Request Participants that were added:
{{fieldChange.to.replace(fieldChange.from, "").replace(",", "").trim()}}
But then I actually facing another problem: the values of {{fieldChange.to}} and {{fieldChange.from}} for Request Partipants are not always in the same order. The "from" value could be: "JIRAUSER1234, JIRAUSER3456" and then the "to" value is: "JIRAUSER1234, JIRAUSER 2345, JIRAUSER3456"
Now it actually gets back to the very start of the problem: How could I find the person that was added... (I wish Jira didn't try to reorder the field but just append the last value to list, then it would make it so much easier :()
I am thinking to split the {{fieldChange.to}} and {{fieldChange.from}} values, that will make them become list, then iterate through them, but then I may need like 4 custom fields to find just one Request Participant, that's not ideal either...
Making the {{fieldChange.to}} field becomes a regular expression might work as well. I actually have to test this out.
Do you have other suggestion around this? I would love to limit saving the data to field as much as possible.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Ooof. Yeah, I don't like having to use a custom field for this. I wonder if you could instead set an issue entity property for "lastAddedParticipant", as mentioned here.
You'd probably have to then do a Re-fetch Issue data before that property is then available as {{issue.properties.lastAddedParticipant}}.
I'll see if I can test this tomorrow, and I think others have done work parsing {{fieldChange}} too.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Darryl Lee @Trang Ngoc Nguyen
Assuming that I have two lists one which contains toString and the other containing fromString, how can I compare them using Jira smart values to find out the new participants added ?
{{fieldChange.fromString.split(",").asJsonStringArray}}
{{fieldChange.toString.split(",").asJsonStringArray}}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Andrian F -
Rereading my original answers I think the final verdict is that this is not possible, as Automation does not have sort or diff functions, nor is it possible to reference to another smart value while iterating through a List.
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.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.