Forums

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

Groupe condition on behavior doesn't work

Boris Demain August 28, 2019

Hi, 

I created a behavior to set a readOnly field depending abour value of an other field.

It's work ! There is an initialiser

"import com.atlassian.jira.component.ComponentAccessor

def N_BDC = getFieldById("customfield_10309")
def Charge = getFieldById("customfield_10205")
def ChargePrev = getFieldById("customfield_10207")
def ChargeReel = getFieldById("customfield_10208")

if (N_BDC.getValue() != "") {
Charge.setReadOnly(true)
ChargePrev.setReadOnly(true)
ChargeReel.setReadOnly(true)
}

else {
Charge.setReadOnly(false)
ChargePrev.setReadOnly(false)
ChargeReel.setReadOnly(false)
}"

then the script in server-side for the field

"import com.atlassian.jira.component.ComponentAccessor
import com.opensymphony.workflow.InvalidInputException


def N_BDC = getFieldById("customfield_10309")
def Charge = getFieldById("customfield_10205")
def ChargePrev = getFieldById("customfield_10207")
def ChargeReel = getFieldById("customfield_10208")

if (N_BDC.getValue() != "") {
Charge.setReadOnly(true)
ChargePrev.setReadOnly(true)
ChargeReel.setReadOnly(true)
Charge.setHelpText("les Charges ne sont plus modifiables car un bon de commande est renseigné")
N_BDC.setHelpText("la Charge n'est plus modifiable car un bon de commande est renseigné")
}

else {
Charge.setReadOnly(false)
ChargePrev.setReadOnly(false)
ChargeReel.setReadOnly(false)
Charge.setHelpText("")
N_BDC.setHelpText("")
}"

But if I add groupe or role condition ( when or except), script doesn't work anymore.

Can someone help me ? 
Should I change my script ?
Should I include rôle condition in script ? How ? (I'm not developper)

Thanks

1 answer

0 votes
Roman Kersky
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 28, 2019

Hi, you need to add a condition to the script 


example group:

 

import com.atlassian.jira.component.ComponentAccessor

def currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()

if (ComponentAccessor.getGroupManager().getGroupsForUser(currentUser)?.find {it.name == "jira-admins"} ){
<your code>

}

 
Boris Demain August 29, 2019

Thanks for your answer,

sadly it's doesn't work. I have two conditions. And even for one doesn't work.

First condition, I want exception for group "jira-administrators"
Second condition, I want exception for role "project-admin" (which is inclued in jira-software-user).

I tried first condition with :

if (ComponentAccessor.getGroupManager().getGroupsForUser(currentUser)?.find {it.name != "jira-administrators"} ){

 Other question, should I put an other "else" with this "if" ?

Sorry for this basic question, as I said, I'm not developper.

Thanks again

Suggest an answer

Log in or Sign up to answer