Forums

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

JMWE Validation - is it possible to check a multi-picker field by groups that user has access to?

Jeremiasz Stróżyk December 17, 2020

Hi,

 

I'm trying to validate a custom filed that is a user multi-picker. I want to send an email to the people specified in that field but there is always a chance that a user will put there a person that is not meant to see that email.

So what I want to do is to check if users picked in that custom filed are members of one specific group. 

Maybe I'm not searching carefully enough but I cannot find any solution.
So far i have managed to do this (not much considering this is a tutorial part mostly):

!!issue.customfield_15206 && issue.customfield_15206.some(it => it.groups == "team_name")

What I've learned is tht the second part is always false as te "it" object has no attribute groups. 
Is there any way to achieve that? Or should I change the approach? Jira Automation maybe?

1 answer

1 accepted

0 votes
Answer accepted
David Fischer
Community Champion
December 17, 2020

Hi @Jeremiasz Stróżyk ,

first of all, Jira Automation won't help you, since it doesn't integrate with workflows and thus doesn't offer any support for workflow validation.

Now, the problem with your Jira expression is that User picker custom fields, unlike standard user fields such as Assignee, don't return User "objects" but just a generic JavaScript object that has no methods.

However, there is a workaround: you can create a "real" user object from an accountId.

Also, your code seems to be checking that at least one user is selected in the custom field, and that at least one user in the field is in the team_name group. I think that's not your goal - you want to check that all users selected in the custom field are in the group, right?

Therefore, this Jira expression should work:

!issue.customfield_15206 || issue.customfield_15206.every(it => (new User(it.accountId)).groups.includes("team_name"))

 Regards,

David 

Jeremiasz Stróżyk December 18, 2020

Hi @David Fischer 

That works perfectly, thanks a lot :)

So simple ;)

Regards,

Jerry

Suggest an answer

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

Atlassian Community Events