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

Problem with Behaviour on Assignee field

Jozef Vandenmooter
Contributor
August 20, 2020 edited

We have a requirement for the Assignee field to have an Assignee in all statuses and all issue types except for the initial status. To avoid having to add a Field Required (JSU) Validator to each and every transition (which would still allow blanking out the Assignee when the issue is static), we implemented a Behaviour:

// Make Assignee field required
import static com.atlassian.jira.issue.IssueFieldConstants.*
// Field is not required during Create
if (getActionName() != "Create"){
// Field is not required in an initial status
if (!(underlyingIssue.getStatus().getName() in ["Backlog","Triage"])){
getFieldById(ASSIGNEE).setRequired(true)
}
}

However, even though the field now appears Required, and it does not accept selecting Unassigned, it still allows being blanked out, which results in the issue being Unassigned. 

It appears a blank field corresponds to "Automatic", which the Behaviour accepts as a non-blank value, and "Automatic" results in a value of "Unassigned" in our projects.

Is there any way to get this to work properly?

 

1 answer

1 accepted

0 votes
Answer accepted
Kirkie
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.
August 20, 2020

I have had success with this. Can you try it out and let me know how it goes?

import static com.atlassian.jira.issue.IssueFieldConstants.*

// Field is not required during Create
if (getActionName() != "Create"){

// Field is not required in an initial status
if (!(underlyingIssue.getStatus().getName() in ["Backlog","Triage"])){
def assignee = getFieldById("assignee")
def user = assignee.getValue()

assignee.setRequired(true)


if((user as String == '-1') || !user){
assignee.setError("You must add an assignee.")
}
else { assignee.clearError() }
}
}
Lwandile Rorwana January 20, 2023

Hi @Jozef Vandenmooter and @Kirkie 

Could you give me a step-by-step guide on implementing this Behavior?

I'm struggling to get this script working. I think I'm missing some libraries.

you help will be highly appreciated in this regard,

Thanks

Lwandile  

Lwandile Rorwana January 20, 2023

these are the errors I'm getting:

[Static type checking] - Cannot find matching method Script614#getActionName(). Please check if the declared type is correct and if the method exists.

[Static type checking] - The variable [underlyingIssue] is undeclared.

Jozef Vandenmooter
Contributor
January 20, 2023

Hi @Lwandile Rorwana ,

Below is the code that works fine for me. 

 

// Make Assignee field required

def issueStatus = underlyingIssue?.getStatus()?.getName()
def issueType = underlyingIssue?.getIssueType()?.getName()
def assignee = getFieldById("assignee")
def user = assignee.getValue()

// Field is not required during Create
if (getActionName() != "Create") {

// Field is not required in initial and end statuses (To Do is not an initial status of the Story and Task)
// if (!(issueStatus in ["Open", "Backlog","Triage","To Do","Closed","Done"]) || (issueStatus == "To Do" && issueType in ["Story","Task"])) {
// This is not in Prod:
if (!(issueStatus in ["Backlog","Triage","To Do","Open","Closed","Done"]) || (issueStatus == "To Do" && issueType in ["Story","Task"]) || getActionName() == "In Progress") {
assignee.setRequired(true)
if ((user as String == '-1') || !user) {
assignee.setError("You must select an Assignee.")
}
else {
assignee.clearError()
}
}
}

Lwandile Rorwana January 21, 2023

Hi @Jozef Vandenmooter ,

Thank you for your prompt feedback.

could you please walk me through on how you implemented this behavior?

It's still not working when I tried it on the script console here are the errors I'm getting. Script consol error .png

 

 

this is how I configured the behavior 

Behaviour Assignee field required on In Progress.png

 

Thanks

Jozef Vandenmooter
Contributor
January 21, 2023

Hi @Lwandile Rorwana 

I don't understand why you're getting those errors... Below screenshots of how I have it set up. 

image.png image.png

Like • Lwandile Rorwana likes this
Lwandile Rorwana February 2, 2023

@Jozef Vandenmooter 

Many thanks this actually worked.

L

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
SERVER
VERSION
8.7.1
TAGS
atlassian, ace, atlassian community event, donation, girls who code, women in tech, malala fund, plan international, kudos, community badge, badge, atlassian badge, International Women’s month, International Women’s Day, women's month, women's day

10 for Change at Atlassian Community Events

Show up and give back by attending an Atlassian Community Event: we’ll donate $10 for every event attendee in March!

Join an Atlassian Community Event!
AUG Leaders

Upcoming Jira Events