Find added Request Participants by smart values

Trang Ngoc Nguyen March 11, 2023

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}}
{{/}}
{{/}}

 

  • fieldChange.to.replace(fieldChange.from, "").replace(",", "").trim() was tested alone and gave the correct value
  • If fieldChange.to.replace(fieldChange.from, "").replace(",", "").trim() is replaced by a string, the returned data is correct
  • If replace fieldChange.to.replace(fieldChange.from, "").replace(",", "").trim() by another simple issue.description smart value (and this value is exactly the same as the working string), then the returned data is empty.
  • The "If" condition work with fieldChange.to.replace(fieldChange.from, "").replace(",", "").trim() and description
  • But when it is for the Request Participants field, it looks like the #if condition doesn't work with two smart values. For some reasons Jira is thinking that the two values are not the same.

Any idea how the above problem can be solved is greatly appreciated.

Thank you very much!

 

2 answers

0 votes
Darryl Lee
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
March 13, 2023

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

Screen Shot 2023-03-13 at 10.21.47 AM.png

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.

Trang Ngoc Nguyen March 16, 2023

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.

Darryl Lee
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
March 16, 2023

Aw man. We really need to be able to SORT both lists and then DIFF them. Hum.

0 votes
Darryl Lee
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
March 12, 2023

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.

Darryl Lee
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
March 12, 2023

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. :-}

Trang Ngoc Nguyen March 13, 2023

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: 

https://community.atlassian.com/t5/Jira-Software-questions/Using-variables-in-functions-in-smart-values-in-JIRA-for/qaq-p/1630769

https://community.atlassian.com/t5/Jira-Software-questions/How-to-create-an-automation-to-set-the-issue-s-last-sprint/qaq-p/2252819#M245069

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.

Darryl Lee
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
March 13, 2023

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.

andrianf July 18, 2023

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

Darryl Lee
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
July 18, 2023

Hi @andrianf -

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. 

andrianf July 19, 2023

@Darryl Lee Ahh I see. Thank you for getting back to me.

Suggest an answer

Log in or Sign up to answer