Are you in the loop? Keep up with the latest by making sure you're subscribed to Community Announcements. Just click Watch and select Articles.

×
Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Celebration

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Scriptrunner Behaviours - Is it possible to chain conditions with 'AND' instead of 'OR'?

Stefan Salzl
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
Jan 16, 2023

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)

image.png

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

1 answer

1 accepted

2 votes
Answer accepted
Florian Bonniec
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
Jan 16, 2023

Hi @Stefan Salzl 

 

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

Stefan Salzl
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
Jan 16, 2023

Hi @Florian Bonniec 

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)

}
Any ideas?
Best
Stefan
Stefan Salzl
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
Jan 16, 2023

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

Like Florian Bonniec likes this

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events