Hi Community, there is an existing Behaviour script that I need to modify. The current script working fine. If the number is 10000 or less it add the user1 to a user field but if the number is greater than 10000 it add user2 to the user field. There is an additional requirement now. If the number is 5000 or less add reporter to user field, if number is more than 5000 and 1000 or less add user1 to user field greater than 10000 should be the same. Here is an example:
5000 or less = Issue Reporter
Greater than 5000 and less than 1000 = User1
Greater than 10000 = User2
How can modify and achieve the requirement?
import com.onresolve.jira.groovy.user.FieldBehaviours
import groovy.transform.BaseScript
@BaseScript FieldBehaviours fieldBehaviours
def userFormField = getFieldById('customfield_11305')
def textFormField = getFieldById('customfield_11306')
Integer number = textFormField.getValue() as Integer
String user = number > 10000 ? 'user2' : 'user1'
userFormField.setFormValue(user)
Thank you,
Your script is very close, though I am not sure what the setserverName() method is from. This script should work in a listener, just put in the name of your server name custom field:
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
def issue = event.issue as Issue
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def customerField = customFieldManager.getCustomFieldObject("customfield_13102")
def customer = issue.getCustomFieldValue(customerField)
def serverName = ""
if(customer == "customerA"){
serverName = "customerA.server"
} else if(customer == "customerB"){
serverName = "customerB.server"
}
if(serverName != ""){
def serverField = customFieldManager.getCustomFieldObjects(issue).find {it.name == "Name of server field"}
def changeHolder = new DefaultIssueChangeHolder()
serverField.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(serverField), serverName),changeHolder)
}
Hi Joshua
Thank you for your reply.
I get an error when I do it like this.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
it flags the error as inappropriate, so I added screenshots.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Could you post the script you're using? Did you change what gave you? It looks like you're trying to get the reporter of the issue to use for the customer variable.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I just changed the name of the customer
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.util.DefaultIssueChangeHolderdef issue = event.issue as Issue
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def customer = Issue.getReporter()
def serverName = ""
if(customer == "customerA"){
serverName = "server"
} else if(customer == "portfolio@customerA.com"){
serverName = "serverA"
}if(serverName != ""){
def serverField = customFieldManager.getCustomFieldObjects(issue).find {it.name == "Environment (Server URL)"}
def changeHolder = new DefaultIssueChangeHolder()
serverField.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(serverField), serverName),changeHolder)
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I see what you mean, I tried something else as well. I've tried it with the reporter, just to see if that would work...
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.