Forums

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

Automation for Jira - Populate Approvers with Project Role?

Fabian Dengel
Contributor
February 12, 2023

Hello all

I am looking to use Automation for Jira to set the Approvers to all members of a project role, but https://support.atlassian.com/cloud-automation/docs/jira-smart-values-projects/ seems lacking this particular case.

I assume I would need to set up a variable and use a smart value? Any hints on how to achieve this? The "Edit issue" action only supports users and copying values from existing issues.

Many thanks in advance!

3 answers

1 accepted

3 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.
February 12, 2023

Hi @Fabian Dengel 

One way to do this would be to call the REST API from a rule to gather the accountId values of people in the role, and then assign them as approvers with a JSON edit.

If you want to try that, here are some references to help:

Kind regards,
Bill

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.
February 13, 2023

 Hi, Fabian.

You are close with that starting point...you will need the JSON for a multi-select user field and the account id values from the response using with an iterator.

{
"fields": {
"Approvers": [ {{#webResponse.body.actors}} { "id":"{{actorUser.accountId}}" }{{^last}}, {{/}}{{/}} ],
}
}

If that does not work, please try writing the expression to the audit log to see what is happening.

Fabian Dengel
Contributor
February 14, 2023

Hey @Bill Sheboy 

Many thanks for providing the iterator! Unfortunately Automation for Jira claimed, the output is not a valid JSON...So I ran it through a JSON validator and seems the very last comma after the square bracked was the culprit, removed it and voilà: Issues edited successfully!

This is the working expression based on your response:

{ "fields": { "Approvers": [ {{#webResponse.body.actors}} { "id":"{{actorUser.accountId}}" }{{^last}}, {{/}}{{/}} ] }}

Thanks again for your support, we made it work in true community fashion so cheers to that :) 

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.
February 14, 2023

Well done, and that is interesting!  I have found the rule parsing inconsistent in accepting a trailing comma for updates. 

Please note I added the conditional processing with {{^last}}, {{/}} handling as I know extra commas inside the list items fail.

1 vote
Karyna Tyrnavska _SaaSJet
Atlassian Partner
February 14, 2023

Hi, @Fabian Dengel !

If you`re ok with Jira plug-ins, try out Business Process Manager. My team has developed this plug-in to manage and optimize complete processes involving different departments and several operations.

Read more about the approval process in BPM in the article or our documentation

Fabian Dengel
Contributor
February 14, 2023

Hi @Karyna Tyrnavska _SaaSJet 

Thanks for the proposal, as you can see we managed at least my use-case with out-of-the-box tooling :)

On that note: I was going to try your app, but it seems your demo does not work (at least when I opened the demo link https://saasjettest.atlassian.net/plugins/servlet/ac/bpm-demo/bpm-main-page-demo?project.key=BPM&project.id=10007 it ran into an error)

Have a good day and kind regards
Fabian

0 votes
Fabian Dengel
Contributor
February 13, 2023

Hey @Bill Sheboy 

Many thanks for your support, much appreciated!

I was able to create the request and retrieve the project role members, however I am stuck at transforming the returned accountIds into a usable JSON to populate the Approvers.

Could you give me another hint on this one?

First, I am creating a smart value variable "roleMembers" from the web request like this:

{{webResponse.body.actors}}

 When I log the value of this request I receive the following (accountIds obfuscated, but syntax identical):

{id=12951, displayName=Fabian (TEST EXTERNAL), type=atlassian-user-role-actor, actorUser={accountId=qm:xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx:xxxxxxx-xxxx-xxxx-xxxx-xxxxxxx}}, {id=12952, displayName=Fabian (TEST), type=atlassian-user-role-actor, actorUser={accountId=qm:xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx:xxxxxxx-xxxx-xxxx-xxxx-xxxxxxx}}, {id=12953, displayName=Fabian Dengel, type=atlassian-user-role-actor, actorUser={accountId=xxxxxxxxxxxxxxxxx}}

 How would I need to transform this in the EDIT action to be accepted?

{
"fields": {
"Approvers": "{{roleMembers")}}",
}
}

I fiddled around with ".asJsonObject" and ".asJsonArray" but my knowledge in that area is lacking and I could not get it to work. I feel I am close, but no cigar :)

Thanks again for pointing me in the right direction!

Suggest an answer

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

Atlassian Community Events