Forums

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

User Picker Field: Condition to stop user from selecting themselves

Uche
Contributor
November 12, 2022

Hey Community,

Need a second pair of eyes here...

I have a user picker custom field on the creation screen for an issue..

I would like to put a condition that checks the field and ensures that it does not match the current reporter. I have tried to take a look online but can't see much.

I have tried writing the User Validator (JMWE app) validator on the create transition for the workflow...and have used the below condition for the user:

issue.reporter.accountId != issue.customfield_11209[0].accountId
This does not work. Does anyone know how to reference currentuser() in JMWE scripts? also can't see this anywhere. Because then rather than using the above could I not just say [customfield].accountId != currentuser()
Thanks

2 answers

1 accepted

4 votes
Answer accepted
Alex Koxaras -Relational-
Community Champion
November 12, 2022

Hi @Uche 

Try something like:

issue.customfield_XXXXX.accountId != user.accountId
Uche
Contributor
November 12, 2022

thanks will give this a try and see if it helps!

Uche
Contributor
November 12, 2022

This works but when testing it on tickets where i am expecting the result to be true. The execution is failing. trying to find out why.

 

thanks

David Fischer
Community Champion
November 12, 2022

Are you getting any error?

Uche
Contributor
November 12, 2022

There was an error during the execution of your Jira expression

Message:
Evaluation failed: "issue.customfield_xxxxx[0]" - Property name must be a string, found: 0 (Number)
Alex Koxaras -Relational-
Community Champion
November 12, 2022

Your single select custom field is not an array. Why are you using the [0]? The code should work exactly as I wrote it in my post.

Alex Koxaras -Relational-
Community Champion
November 12, 2022

On the validation if this 

issue.customfield_XXXXX.accountId != user.accountId

is true, then the validation pass and the transition should continue. If the the user picker field is equal to the current user, then the validation should fail and the transition wouldn't continue.

Uche
Contributor
November 12, 2022

it defaults to [0] when searching the custom field in the issue fields tab for JMWE. accountId doesn't seem to be a recognised property without it.

There was an error during the execution of your Jira expression

Message:
Evaluation failed: "issue.customfield_11209.accountId" - Unrecognized property of `issue.customfield_11209`: "accountId" ('accountId'). Type null does not have any properties
Uche
Contributor
November 12, 2022

Seem to have got rid of that error message but still not seeing the correct result when testing.

Getting a false result even though my user is the current user and also the user in the custom field. Will mess around with it.

thanks

David Fischer
Community Champion
November 12, 2022

The error you reported earlier means that the field is empty. Were you testing with a value for that custom field?

0 votes
David Fischer
Community Champion
November 12, 2022

Hi @Uche ,

Is your field a single-user picker or multi-user picker?

Also, did you use the "Issue Fields" help tab to figure out how to test the value of the custom field?

Uche
Contributor
November 12, 2022

Hi @David Fischer 

It is a single-user picker. and yes i did use the help tab but there is no info there that helps with the current user aspect of it,

Thanks

David Fischer
Community Champion
November 12, 2022

Right. The current user is described on the Globals help tab. You can refer to it as user.accountId

Uche
Contributor
November 12, 2022

classic. was looking on the wrong tab. seen thanks.

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