Forums

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

How to add a custom multi user picker field users to a particular project role in JIRA server?

cloud jira
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
October 12, 2022

Hi Team,

Below requirement in JIRA SERVER.

I have a multi user picker custom field like "Viewers".

When I add the users in the "Viewers" field in the create and edit issue, people in this field are automatically added to the "Developers" project role. 

Viewers(custom multi user picker field)  --> Developers (role)

--> I have Script Runner and JMWE add-ons.

 

Thanks

1 answer

3 votes
David Fischer
Community Champion
October 12, 2022

Hi @cloud jira ,

first of all, you specified "Cloud" as your deployment type when posting this question, but you mentioned you want the answer for Jira Server. That's confusing.

Anyway, on Jira Server, you can create an Event-based Action from JMWE that listens to changes to the Viewers field and add a Scripted (Groovy) post-function to that action with a script like:

import com.atlassian.jira.bc.projectroles.ProjectRoleService
import com.atlassian.jira.util.SimpleErrorCollection
import com.atlassian.jira.security.roles.ProjectRoleActor

ProjectRoleService prs = getComponent(ProjectRoleService)
SimpleErrorCollection errCollection = new SimpleErrorCollection();
def projectRole = prs.getProjectRoleByName("Developers", errCollection)

def userKeys = issue.get("Viewers")*.key
prs.addActorsToProjectRole(userKeys, projectRole, issue.projectObject, ProjectRoleActor.USER_ROLE_ACTOR_TYPE, errCollection)
cloud jira
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
October 12, 2022

Hi David,

I am facing a problem.

--> If I remove users from the "Viewers" field they should leave the role automatically. (This function is not happening automatically)

--> If I add multiple users in the "Viewers" field at onetime, all those who have added are being added in the "Developers" role automatically.

--> If I add one user in the "Viewers" field, that user is adding in the "Developers" role automatically.

--> If I added 2nd, 3rd users after adding the first user in the "Viewers" field. 2nd, 3rd users are not adding in the "Developers" role.

Note: After adding 1st user, if I add one or multiple users in the "Viewers" field, all those who have added are not being added in the "Developers" role automatically.

-->For ex: I have added Anitha in the Viewers field, again I want to add one more user Srilakshmi along with Anitha, So I added Srilakshmi with Anitha. But Srilakshmi is not adding in the Developers role.

 Please find below image.

Please help me in this.

 

image.pngimage.png

 

Thanks.

Vinodh October 16, 2022

Hi @David Fischer 

Can you please let me know how it can be done.

Thanks!

David Fischer
Community Champion
October 17, 2022

@Vinodh ,

can you share the configuration of the event-based action you have configured?

As for removing users who were removed from the Viewers field from the project role, this is more complicated as the user could be in the Viewers field of two issues, and if you remove that user from the Viewers field of only one issue, you shouldn't remove that user from the project role since they are still mentioned in the Viewers field of the other issue. Or did I misunderstand something?

Vinodh October 17, 2022

Hi @David Fischer 

There is small misunderstanding, let me give you a clear view

For ex: I update viewers multi user picker field with one user and after sometime I may require couple of users additionally to be added. During this case the first user gets updated properly but the users updated aftr sometime is not getting updated in the project roles.

And when we update multiple users at a single go it's working fine,but adding users at multiple intervals are not getting updated 

 

 

Regards 

Vinodh A

David Fischer
Community Champion
October 17, 2022

Again, can you share a screenshot of your event-based action?

mahammad rafi October 17, 2022

 

Hi @David Fischer 

Please don't be confuse. We three are from same team
We have implemented script in below event based post-function. 

image.png

David Fischer
Community Champion
October 17, 2022

I was actually more interested in the configuration of the event-based action itself... Can you share a screenshot of that?

mahammad rafi October 17, 2022

We are triggering the post function with below listener

image.png

mahammad rafi October 17, 2022

@David Fischer 

Please help us in the scripting part.

 

Thanks

Rafi

David Fischer
Community Champion
October 17, 2022

@mahammad rafi you need too create an event-based action (which is a JMWE feature), the script I provided will not work with scriptrunner. 

mahammad rafi October 17, 2022

@David Fischer 

Even if I run JMWE Event based actions also script is working as same like working above. There is no difference between direct post-function and JMWE event based action listener. 

David Fischer
Community Champion
October 18, 2022

An event-based action will run every time the source field (Viewers) is modified, unlike a post-function on a transition.

Can you share the screenshot of your event-based action?

Vinodh October 18, 2022

@David Fischer 

Find screen shots of JMWE Event based action.

Configuration.PNGEvent based action Screen shot.PNG

 

So as disussed in above conversation, Can you Please check adding a user initially and adding 2nd user after a min and updating the field in your system, So you can have a clear picture 

 

 

Regards

Vinodh A

David Fischer
Community Champion
October 19, 2022

Hi @Vinodh ,

in "Event", you need to pick "Issue Field Value Changed", and then pick the Viewers field under "Fields to monitor".

Suggest an answer

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

Atlassian Community Events