Forums

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

Check user field while editing an issue

Andreas Lorz
Contributor
April 25, 2019

Hi,

got an user picker field. When the issue is editing I want to check that the user in a certain user picker field is not the same as the logged in user (the person who is currently editing the issue).

Thought this would be easy with ScriptRunner Behaviours but somehow its not working.

It doesn't recognize the condition when editing from a valid user to my user.

behaviours.PNG

Thanks in advance.

 

1 answer

1 accepted

0 votes
Answer accepted
Antoine Berry
Community Champion
April 26, 2019

Hi @Andreas Lorz ,

It seems indeed to trigger only when you save the field value, so it will not dynamically display the error. Instead you could just use a script without condition on this field : 

import com.atlassian.jira.component.ComponentAccessor
import com.onresolve.jira.groovy.user.FieldBehaviours
import groovy.transform.BaseScript

@BaseScript FieldBehaviours fieldBehaviours

def responsibleForReal = getFieldById(getFieldChanged())
def responsibleForRealValue = responsibleForReal.getValue()

def currUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
String currUserKey = currUser.getKey()

if (currUserKey == responsibleForRealValue){
responsibleForReal.setError("Please select someone else as the responsible for realization")
}
else {
responsibleForReal.clearError()
}

Antoine

Andreas Lorz
Contributor
April 26, 2019

This works. Thanks @Antoine Berry 

Like Antoine Berry likes this
Antoine Berry
Community Champion
April 26, 2019

You're welcome ! Please consider accepting the answer if you are satisfied with it so other users can benefit from it as well.

PD Sheehan
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.
April 26, 2019

The "condition" is used to define where one of the three attributes above (Optional, Writable, Shown). 

While the server-side script is where you would put more complex conditions and actions such as what was suggested by Antoine.

Suggest an answer

Log in or Sign up to answer