Forums

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

Set Assignee based on custom field in Create screen

Kamal Iqlaas Ismail October 27, 2021

Hi everyone,

Hope this question finds you well.

On create screen, I want to be able to determine who is the assignee based on the chosen value of a drop down custom field. (using Behaviour Script)

I looked here but the answers given seem to point after the issue has been created.

And others that I looked also most of them  handle after the issue has been created,

Here is my code:

 

void setAssignee(){

FormField ffAssignee = getFieldByName("Assignee")

String value = getFieldById(customfield_id).getFormValue()

if (value in HERE){

ffAssignee.setAssigneeId("name.lastname")

} else if (value in THERE){

ffAssignee.setAssigneeId("name.lastname")

}

}


I tried this as suggested in here (given in link above as answer), but still could not get it to work

void setAssignee(){

FormField ffAssignee = getFieldByName("Assignee")

String value = getFieldById(customfield_id).getFormValue()

if (value in HERE){

ffAssignee.setAssignee(ComponentAccessor.getUserManager().getUserByKey("name.lastname"))

} else if (value in THERE){

ffAssignee.setAssignee(ComponentAccessor.getUserManager().getUserByKey("name.lastname"))
}
}


Any pointers would be helpful!

2 answers

1 accepted

0 votes
Answer accepted
Kamal Iqlaas Ismail October 27, 2021

Here is the working code. just need to change the field pickup to getFieldChanged()

 

void setAssignee(){

FormField ffAssignee = getFieldByName("Assignee")

FormField desiredField = getFieldById(getFieldChanged())

String value = desiredField.getFormValue()

if (value in HERE){

ffAssignee.setFormValue("name.lastname")

} else if (value in THERE){

ffAssignee.setFormValue("name.lastname")

}

}

 

Hope this helps anyone who is facing same issue.

Stay safe everyone

0 votes
Fazila Ashraf
Community Champion
October 27, 2021

Hi @Kamal Iqlaas Ismail 

Please make an updateIssue after setting the value and see whether change is reflected. Refer to the function in  https://docs.atlassian.com/software/jira/docs/api/8.0.1/index.html?com/atlassian/jira/issue/IssueManager.html

Kamal Iqlaas Ismail October 27, 2021

Hi @Fazila Ashraf , yes the change is reflected. I tested on another field without the need to use the updateIssue.

On create screen, we want to show the user the Assignee (system field) for the value (a dropdown) before the issue gets created, not after.

Sorry the updateIssue function does not seem to help here.

Suggest an answer

Log in or Sign up to answer