Help with scriptrunner code

Adam G May 29, 2021

Hi im trying to assign an issue based on a radio button selected but my code is not working. Radio has two options and based on the option selected a different user should be assigned to the issue when the transition happens. Here is what i have done so far in a script editor. Thanks for any help.

IssueManager im = ComponentAccessor.getIssueManager()
MutableIssue issue = im.getIssueObject("SD-....")

ApplicationUser assignee
UserManager umgr = ComponentAccessor.getUserManager()

final customFieldName = "radioCF"
def customFieldManager = ComponentAccessor.customFieldManager
def dot_cf = customFieldManager.getCustomFieldObjects(issue).find { it.name == customFieldName }

def dot_value = dot_cf.getValue(issue)

if (dot_value == "option1")
{
assignee = umgr.getUserByName('user1')
issue.setAssignee(assignee)

} else if (dotyczy_value == "option2") {
assignee = umgr.getUserByName('user2')
issue.setAssignee(assignee)
}

1 answer

1 accepted

3 votes
Answer accepted
Vikrant Yadav
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
May 29, 2021

Hi @Adam G  Try below script , add this in Post function . I have tested on my side. It's working.

import com.atlassian.jira.issue.MutableIssue;
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.fields.CustomField

final String userName1 = "user1"
final String userName2 = "user2"

def customFieldManager = ComponentAccessor.getCustomFieldManager()
def customfield = customFieldManager.getCustomFieldObject("customfield_27460")

if (issue.getCustomFieldValue(customfield).toString() == "Low") {
def user = ComponentAccessor.userManager.getUserByName(userName1)
issue.setAssignee(user)
}
else if (issue.getCustomFieldValue(customfield).toString() == "Medium"){
def user = ComponentAccessor.userManager.getUserByName(userName2)
issue.setAssignee(user)

}
Vikrant Yadav
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
May 29, 2021

Kindly change Low and Medium value as per your radio button field values. 

Like Adam G likes this
Adam G May 29, 2021

Thank you so much. Works like a charm :). I can move forward because it's not the end of it. Its only the first step of the workflow. Now i need to transition to different status based on the second radio option.  

Like Vikrant Yadav likes this
Vikrant Yadav
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
May 29, 2021

@Adam G  Great :) Glad to hear it works for you. 

For transition, you no need to write script .Use Fast track transition an issue based on Condition. Hope it works for you. 

 

Thanks!

Like Jakob likes this

Suggest an answer

Log in or Sign up to answer