Forums

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

Can We create message error if user pick wrong person ( in jira group)

Tyas Iglecias November 17, 2020

Hi Guys,

1.  I have Field
"Project Changes" : Infrastructure, Security, Application

2.  I have Jira Group :
- Infra Team, members A, B, C

- Security Team,  members D,E

- Aplication Team, members F,G,H
 

3.  I Field "Developer" ( User Picker)

 

Can we maka error message "Unsuitable developer with Project Change type" if:

Field  "Project Changes" =  Security
Field "Developer" = H

I have Addon JMWE

Regards,
Tyas

2 answers

1 accepted

1 vote
Answer accepted
David Fischer
Community Champion
November 17, 2020

Hi Tyas,

you can create a "Build-your-own" Validator, but I cannot write the Jira expression for you as it needs to use issue field IDs which are specific to your instance. However, you can use the "Issue Fields" help tab below the editor to find these IDs.

I'm also not clear on why you mentioned the Jira group, as you don't seem to be referring to it in the validation.

Can you clarify?

David

Tyas Iglecias November 17, 2020

Hi David,

what I mean about Jira Group its like this picture2020-11-18_10-35-59.jpg

 

what I want, If user change status, JMWE sends an email notification to the selected person in Field "Developer" ( its clear,  I can do that used Post Fungtion used JMWE)

and what I need the status doesn't change ( message error) if the "Developer" field is incorrectly filled (mismatch between "Project Change" field and "Developer" field based on "Jira Group")

 

Regards,
Tyas

David Fischer
Community Champion
November 18, 2020

Oh, I think I got it. Each value of the "Project Changes" field has a corresponding "group" named after it (or kind of, based on your initially question: Infrastructure => Infra Team, Security => Security Team, Application => Application Team), and you want to force the user selected in the Single-user picker field named "Developer" to belong to the group matching the Project Changes field value. Right?

You can achieve this using a Build-your-own Validator, with the following script:

new User(issue.customfield_12105.accountId).groups.includes(issue.customfield_12345.value + " Team")

Note that you will need to replace customfield_12105 with the field ID of the Developer Single-user Picker custom field, and customfield_12345 with the field ID of the Project Changes single select custom field. You'll find them using the "Issue Fields" help tab below the expression editor.

Tyas Iglecias November 22, 2020

Hi Dave, 

IT try used it to my transition but its not work
Developer Single-user Picker custom field = 12097
Project Changes single select custom field = 12344

new User(issue.customfield_12097.accountId).groups.includes(issue.customfield_12344.value + " Team")


and I'm inspired and develop your script,

(new User(issue.customfield_12097.accountId).groups.includes("Application Team") && !!issue.customfield_12344 && issue.customfield_12344.value == "Application")
||
(new User(issue.customfield_12097.accountId).groups.includes("Security Team") && !!issue.customfield_12344 && issue.customfield_12344.value == "Security")
||
(new User(issue.customfield_12097.accountId).groups.includes("Infra Team") && !!issue.customfield_12344 && issue.customfield_12344.value == "Infrastructure")


Is your script making mine shorter? or what I made exactly what you meant?


David Fischer
Community Champion
November 23, 2020

My script was shorter but assumed that the group name was exactly the concatenation of the select field value and " Team", which is not the case for Infrastructure. So your script is best in your case.

Tyas Iglecias November 24, 2020

Hi David,

Thanks for teaching me

0 votes
Amir Katz (Outseer)
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.
August 17, 2021

Great answer by @David Fischer , but I have one question:

Wat's the purpose of the 'new' keyword?

I have not seen the 'new' mentioned in the documentation, which, not incidentally I guess, was written by the same David...:

https://innovalog.atlassian.net/wiki/spaces/JMWEC/pages/935362565/Build-your-own+scripted+Validator

David Fischer
Community Champion
August 17, 2021

The "new" keyword creates a new instance. For User objects, it's documented here: https://developer.atlassian.com/cloud/jira/platform/jira-expressions-type-reference/#user

It's also documented on the "Data Types" help tab of the script editor, for the User data type:

image.png

Amir Katz (Outseer)
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.
August 17, 2021

Yes, I can see it documented in both places, but there is no explanation why one would have to use the New construct. 

I see that New is used for user , issue, and a few more types.

The usual JMWE validators use constructs like 'issue.comments', or 'issue.customfield_12345'.

So can please you explain when one needs to use the New construct? 

I would also recommend that the JMWE documentation would explain this topic so that JMWE users would know when New is needed and when it's not.

Thanks for your patience & help!

David Fischer
Community Champion
August 18, 2021

Yes, you are right, the JMWE documentation wasn't updated properly when Atlassian introduced the new instruction. It is used to create the corresponding object based on an ID (a string). It's mostly useful when accessing custom fields, because Jira expressions return raw "JavaScript hashes" (maps) as the value of custom fields, instead of real objects. For example:

issue.reporter

returns a User object, but

issue.customfield_12345

where customfield_12345 is a Single-user picker custom field returns a non-typed hash of key-value pairs that lacks the Jira expression-specific properties and methods of the User type.

Therefore, 

issue.reporter.groups

works, but 

issue.customfield_12345.groups

doesn't, and the workaround is:

new User(issue.customfield_12345.accountId).groups

IMHO, this is a poor design choice on Atlassian's part (when they designed the Jira expressions language) but they can't change it now as it would break existing code.

Like Amir Katz (Outseer) likes this
Amir Katz (Outseer)
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.
August 22, 2021

Thanks for the excellent explanation of this mystery.

And I totally agree with "poor design choice". It's not the only place...

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