I need to insert a post function into a workflow that says if a custom field value is <200, set the assignee to Person A, and if the value is greater than or equal to 200, set the assignee to Person B.
I have scriptrunner, please may someone help me with this script!
Hi @Fazila Ashraf, thanks for your reply.
In that code;
import com.atlassian.jira.component.ComponentAccessor import com.atlassian.jira.issue.MutableIssue String userName; switch(ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("fieldname").toString()){ case "1": userName = "user1";break; case "2": userName = "user2";break; case "3": userName = "user3";break; } issue.setAssignee(ComponentAccessor.getUserManager().getUserByName(userName))
I am not sure where/how to define the different cases. I think i should be using the statements
if (number >= 200)
and
if (number < 200)
somewhere in the code, but I am unsure how to incorporate this. I'm afraid I am very new to ScriptRunner and groovy, any help would be hugely appreciated!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Yes, you should be using an 'If .. else" statement for your use case
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I have got the following code:
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.user.util.UserManager
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.event.type.EventDispatchOption
def number = ComponentAccessor.getCustomFieldManager().getCustomFieldObject("customfield_10202").getValue(issue)
if ((int) number >= 200){
issue.setAssignee(ComponentAccessor.getUserManager().getUserByName("francismiers"))
}
else{
issue.setAssignee(ComponentAccessor.getUserManager().getUserByName("charlotteflowerdew"))
}
log.error(number)
The error from the log says: "Cannot invoke method getValue() on null object".
I'm sure this is a minor detail I have got wrong, but like i said i am new to groovy so any advice would be apprieciated.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
For anyone else interested, the code below worked for me:
import com.atlassian.jira.component.ComponentAccessor
log.info(issue)
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def customField = customFieldManager.getCustomFieldObjectByName("Value (£)")
def number = customField.getValue(issue)
if ((int) number >= 200){
issue.setAssignee(ComponentAccessor.getUserManager().getUserByName("Username A"))
}
else{
issue.setAssignee(ComponentAccessor.getUserManager().getUserByName("Username B"))
}
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.