Forums

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

Update custom field defined as a people picker in Scriptrunner Listener

Dave Cuff August 21, 2020

Any volunteers for an answer?

I am trying to update a custom field defined as a people picker and I keep getting a java error saying " java.lang.String cannot be cast to com.atlassian.jira.user.ApplicationUser". I assume my definition of respBEMValue is incorrect but can't find documentation on how to do it correctly.

Here is my script
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.jira.issue.customfields.option.LazyLoadedOption
//
// set the responsible BEM based on primary business area
//
def primaryBusinessAreaField = customFieldManager.getCustomFieldObjects(issue).findByName("Primary Business Area Impacted")
def respBEMField = customFieldManager.getCustomFieldObjects(issue).findByName("Responsible BEM")
def respBEMValue

LazyLoadedOption primaryBusinessAreaOption = (LazyLoadedOption) issue.getCustomFieldValue(primaryBusinessAreaField)

if (primaryBusinessAreaOption?.getValue() == "Africa" ||
primaryBusinessAreaOption?.getValue() == "Fresh Foods" ||
primaryBusinessAreaOption?.getValue() == "Freshmark" ||
primaryBusinessAreaOption?.getValue() == "Group Engineering" ||
primaryBusinessAreaOption?.getValue() == "Liquor Stores" ||
primaryBusinessAreaOption?.getValue() == "Meat Markets" ||
primaryBusinessAreaOption?.getValue() == "Store Operations" ) {
respBEMValue = "mamarais"
} else if (primaryBusinessAreaOption?.getValue() == "Finance" ||
primaryBusinessAreaOption?.getValue() == "Human Resources" ||
primaryBusinessAreaOption?.getValue() == "Legal & Compliance" ||
primaryBusinessAreaOption?.getValue() == "Properties" ) {
respBEMValue = "cmmohamed"
} else if (primaryBusinessAreaOption?.getValue() == "Plan") {
respBEMValue = "cmsamuels"
} else if (primaryBusinessAreaOption?.getValue() == "Customer (incl Marketing & Strategy & Innovation)" ||
primaryBusinessAreaOption?.getValue() == "Information Technology (IT)" ||
primaryBusinessAreaOption?.getValue() == "Marketing") {
respBEMValue = "cesnyders"
} else if (primaryBusinessAreaOption?.getValue() == "Checkers Food Services (CFS)" ||
primaryBusinessAreaOption?.getValue() == "Furniture" ||
primaryBusinessAreaOption?.getValue() == "Pharmaceutical" ||
primaryBusinessAreaOption?.getValue() == "OK Franchise") {
respBEMValue = "cbrits"
} else if (primaryBusinessAreaOption?.getValue() == "Procure" ||
primaryBusinessAreaOption?.getValue() == "Supply Chain") {
respBEMValue = "jgoosen"
} else if (primaryBusinessAreaOption?.getValue() == "Computicket" ||
primaryBusinessAreaOption?.getValue() == "Financial Services") {
respBEMValue = "rianalouw"
} else {
respBEMValue = ""
}

respBEMField.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(respBEMField), respBEMValue), new DefaultIssueChangeHolder())

0 answers

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
SERVER
TAGS
AUG Leaders

Atlassian Community Events