Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Jira scriptrunner assign user when issue is created Edited

Hello,

 

We are using scriptrunner to assign an user when the issue is created. But now everytime the user Robine is assigned to the issue. Can someone check this scriptrunner code?

It worked before so maybe there are some changed i need to make in de code.

 

import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.MutableIssue;
import com.atlassian.jira.issue.IssueManager;
import com.atlassian.jira.event.type.EventDispatchOption;

def issueManager = ComponentAccessor.getIssueManager();
def customFieldManager = ComponentAccessor.getCustomFieldManager();
def unitInCharge = customFieldManager.getCustomFieldObjectByName("Unit in Charge");

MutableIssue issue = (MutableIssue) event.issue

String unit = issue.getCustomFieldValue(unitInCharge).toString();

final String PLANT_MANAGER = "robine";
final String LOGISTICS = "theo";
final String PRODUCTION = "robine";
final String HSEQ = "dick";
final String MAINTENANCE = "hans";
final String PROCESS_ENGINEERING = "krijn";
final String PROJECT_ENGINEERING = "pieter";
final String LABORATORY = "martin";
final String HUMAN_RESOURCES = "robine";
final String OPERATIONS = "krijn";
final String FINANCE = "vincent";

switch(unit) {
case "Plant Manager":
issue.setAssigneeId(PLANT_MANAGER);
break;

case "Logistics":
issue.setAssigneeId(LOGISTICS);
break;

case "Production":
issue.setAssigneeId(PRODUCTION);
break;

case "HSEQ":
issue.setAssigneeId(HSEQ);
break;

case "Maintenance":
issue.setAssigneeId(MAINTENANCE);
break;

case "Process Engineering":
issue.setAssigneeId(PROCESS_ENGINEERING);
break;

case "Project Engineering":
issue.setAssigneeId(PROJECT_ENGINEERING);
break;

case "Laboratory":
issue.setAssigneeId(LABORATORY);
break;

case "Human Resources":
issue.setAssigneeId(HUMAN_RESOURCES);
break;

case "Operations":
issue.setAssigneeId(OPERATIONS);
break;

case "FINANCE":
issue.setAssigneeId(FINANCE);
break;

default:
break;
}

Thanks! 

1 answer

0 votes
Antoine Berry Community Leader Feb 10, 2020

Hi @b_onderwater ,

Have you used some logs to display the unit value and make sure the correct case was triggered? 

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Marketplace Apps & Integrations

5 mobile apps for Jira Cloud to boost productivity

  It’s very important to have access to the workflow process from anywhere. Especially if you manage the work of others. There is no difference whether you’re out of office, or drive a ca...

203 views 2 5
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you