Forums

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

Auto-set Assignee based on Cascade field select

Kiranped September 21, 2020

Below is my code using in behaviour script- not working

Requirement: Auto-set Assignee based on cascade field select

 

import com.atlassian.jira.component.ComponentAccessor

def formhddmo = getFieldByName("cascadefield")
def assigneeField = getFieldById("assignee")
def formassign = getFieldByName("assignee")

//log.debug("----------------> " + formhddmo.getValue())
//log.debug("----------------> " + formhddimos.getValue())

String userName="kiran.p@xxx.com";

List<String> listString = formhddmo.getValue() as List<String>

def parentValue = listString.get(0)

switch(parentValue){
case "Dfgd ACC ART": userName = "jay.asdfsd@xxx.com";break;
case "HDdfgdD Infrastructure ART": userName = "Bryan.asdfsd@xxx.com";break;
case "Dfgsdf Command Flow ART": userName = "Pawan.asfasd@xxx.com";break;
case "Power and Performance": userName = "ajhsdg.Begum@xxx.com";break;
case "FWsdgdTest & Val": userName = "Alexander.Peladtt@xxx.com";break;
case "Sdfgsdfg Fmwre":
switch(formhddimos.getValue()){
case "zdsfgds": userName = "Adam.asdfsd@xxx.com";break;
case "Custosadfmer Enablement": userName = "benjamin.lundd@xxx.com";break;
case "Architecture": userName = "robert.medyer@xxx.com";break;
}
case "Rding Subsystems":
switch(formhddimos.getValue()){
case "Dfgsdfg Integration": userName = "takanori.asdfasd@xxx.com";break;
case "Elec FW": userName = "timothy.schmdalz@xxx.com";break;
}

}
// set Assignee
getFieldById(ASSIGNEE).setFormValue(userName)

1 answer

0 votes
Gustavo Félix
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 23, 2020

Hi @Kiranped 
Have you tried the username instead of the email. 

For example, assuming  "jay.asdfsd@xxx.com" email is "jay" username.
case "Dfgd ACC ART": userName = "jay";break;

Kiranped September 23, 2020

email and username are the same

Gustavo Félix
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 23, 2020

Ok. 
Do you have this import in your code?

import static com.atlassian.jira.issue.IssueFieldConstants.ASSIGNEE
Kiranped September 23, 2020

@Gustavo Félix 

Thanks for the reply.

Yes, I have.

My Jira version is 8.5.3, it's strange to even the below snippet not working


def assigneeField = getFieldById("assignee")

String userName="kiran.p@xxx.com"

assigneeField.setFormValue(userName)
Gustavo Félix
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 24, 2020

This exact code works for me:

import com.atlassian.jira.componentAccessor
import static com.atlassian.jira.issue.IssueFieldConstants.ASSIGNEE

def username = "XXXX";
getFieldById(ASSIGNEE).setFormValue(username)

Can you try it with your username ?

Suggest an answer

Log in or Sign up to answer