Hi Community,
I need help to fix a behaviour script. I have a script that adds user1 and user2 base on the amount added in a CFText. For example, if the amount is 1000 or less it adds user1 to the UserCF or if it is more than 1000 then add user2 to UserCF. That part is working fine and I have the following first script for that.
This is the existing and working script without components added.
import com.atlassian.jira.bc.project.component.ProjectComponent
import com.onresolve.jira.groovy.user.FieldBehaviours
import groovy.transform.BaseScript
@BaseScript FieldBehaviours fieldBehaviours
def userFormField = getFieldById('customfield_14000')
def textFormField = getFieldById('customfield_12500')
Integer number = textFormField.getValue() as Integer
String user = number > 10000 ? 'user2' : 'user1'
userFormField.setFormValue(user)
Now I'm trying to make it work with two of the components. For example, if component "Refunds" is selected and the amount is 1000 or less it should add user1 to the UserCF or if component "Refunds" is selected and the amount is more than 1000 then it should add user2 to UserCF. For the rest of the components, it should do nothing. The project has about 10 components but we want that condition should apply for two components only. For the rest of the components regardless of the amount, it should be applied.
import com.atlassian.jira.bc.project.component.ProjectComponent
import com.onresolve.jira.groovy.user.FieldBehaviours
import groovy.transform.BaseScript
@BaseScript FieldBehaviours fieldBehaviours
def userFormField = getFieldById('customfield_14000')
def textFormField = getFieldById('customfield_12500')
//-----------------------
def components = getFieldById(getFieldChanged()).value as List<ProjectComponent>
if(components.any{it.name == 'Refund'}){
Integer number = textFormField.getValue() as Integer
String user = number > 10000 ? 'user2' : 'user1'
userFormField.setFormValue(user)
}
Thank you for your help.