Hi Community,
I would like to set a field requirede in case if some conditions are met:
WHEN
- specific status (eg. in Progress)
AND
- current user has a specific role (eg. Users)
When I add those conditions in a behaviour for a field the work together in an 'OR' combination which means
even if status is not the specified status (eg. in Progress) BUT your user has the role "Users" the field is required.
What I would need is that the field is only required if an issue is in status "in Progress" AND user has role "Users" --> BOTH conditions needs to be met in order to set the field required.
Is there any possibility to configure this with standard configuration in behaviours (like the settings you could choose) or do I have to write a custom condition script for this?
Thanks in advance.
Best
Stefan
You can do it using script by adding a server side script then use if statement.
https://docs.adaptavist.com/sr4js/latest/features/behaviours/api-quick-reference
if(getActionName() == "XXXX" AND .....){
getFieldById(getFieldChanged()).setRequired(true)
}
Regards
Thanks for your input. I need to "rebuild" the out of the box functionality of scriptrunner but I need both conditions to be checked.
So normally a behaviour fires whenever I open an issue in edit mode.
How can the same behaviour done with script? I need the field to occur required when issue opens in edit mode and conditions match (not by any field change from your example).
I tried the following script but didn´t work:
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.security.roles.ProjectRoleManager
def projectManager = ComponentAccessor.projectManager
def wfManager = ComponentAccessor.workflowManager
def projectRoleManager = ComponentAccessor.getComponent(ProjectRoleManager)
def user = ComponentAccessor.jiraAuthenticationContext.getLoggedInUser()
def iMngr = ComponentAccessor.issueManager
def currentProj = projectManager.getProjectByCurrentKey("DEV")
log.warn(currentProj)
def userRole = projectRoleManager.getProjectRole("Users")
log.warn(userRole)
// check if iser current user is in project role --> returns boolean (true/false)
def userIsUsersRole = projectRoleManager.isUserInProjectRole(user, userRole, currentProj)
log.warn(userIsUsersRole)
def currentIssueWF = wfManager.getWorkflow(underlyingIssue)
log.warn(currentIssueWF)
def currentState = underlyingIssue.getStatus().name
log.warn(currentState)
def stateIsToDo = currentState == "To Do"
log.warn(stateIsToDo)
// conditions for field
if(stateIsToDo || userIsUsersRole){
getFieldByName('Menge/Häufigkeit').setRequired(true)
}
else {
getFieldByName('Menge/Häufigkeit').setRequired(false)
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
It works now. Scriptrunner didn´t like the name of my field as I used the getFieldByName() =S
Thanks for your time and input.
Best
Stefan
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.