Reset assignee to "Automatic" in Jira Behaviour script

Neil Arrowsmith
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.
June 15, 2017

I'm using a Behaviour to set a different default assignee on the Create screen, if a certain custom field (radio button) value is picked.

This works fine, but I want the behaviour to change the assignee back to "Automatic" if the same custom field is changed again. I can't get this part to work, having tried various different things in setFormValue (including "automatic", "-1", null).

Here's my server side script:

import static com.atlassian.jira.issue.IssueFieldConstants.ASSIGNEE
def raisedfromField = getFieldByName("Raised From")
if (raisedfromField.getValue() == "Support") {
    // Set assignee to SJM
    getFieldById(ASSIGNEE).setFormValue("supportjiramanager")
}
else {
// Set assignee back to "Automatic", in case user picks Support
// and then changes their mind getFieldById(ASSIGNEE).setFormValue("-1") }

Any ideas?

1 answer

0 votes
Jenna Davis
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.
June 26, 2017

Hello, 

I think you need some sort of statement on your 'else' that checks if the form value is already set to "supportjiramanager" or not. 

Something like this:

import static com.atlassian.jira.issue.IssueFieldConstants.ASSIGNEE
def raisedfromField = getFieldByName("Raised From")
if (raisedfromField.getValue() == "Support") {
    // Set assignee to SJM
    getFieldById(ASSIGNEE).setFormValue("supportjiramanager")
}
else if (getFieldById(ASSIGNEE) == "supportjiramanager") {
    // Set assignee back to "Automatic", in case user picks Support
    // and then changes their mind
    getFieldById(ASSIGNEE).setFormValue("automatic")
}

 Regards, 

Jenna

Neil Arrowsmith
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.
June 27, 2017

Thanks Jenna, but still not working. I don't think there's a problem with the else (the version i'm now using has another setFormValue to a specific user in the else - since it happens that the defalt assignee settings are such that it almost always goes to that user anyway - and that works fine). The problem is what goes in setFormValue if I want the field to revert back to auto-assign. "automatic" doesn't work, neither does "Automatic", "-1", "1" or null.

Although I guess your advice does help in stopping the field changing unnecessarily if the user keeps clicking different Raised From options, so I might use that.

Thanks again

 

Jenna Davis
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.
June 27, 2017

How did you have the Behavior set up? As an initializer or just on that form field? You should need some form of statement to check if the field is set to 'supportjiramanager'. If the behavior only ran when the issue initially creates that might have been the problem also as it would never run the function again to check if field got edited.

If you found a workaround though, great! I'm sorry it took so long to get an answer to you for this question. 

Jenna

 

 

Neil Arrowsmith
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.
June 28, 2017

Hi Jenna

It's set up as a validation script on the "Raised From" field. I don't have an initialiser function setup.

Thanks again for your help on this

Neil

Deleted user October 3, 2017

Hey you two

I currently have the same issue but would really need to be able to reset the assignee back to automatic.

In my case, the user sets the issue type to "Idea" which should set the assigne to a specific user and lock the field. This works so far. Resetting back to automatic when changing the project or the issuetype or both does not however.

Here's my script.

import com.atlassian.jira.component.ComponentAccessor
import com.onresolve.jira.groovy.user.FieldBehaviours
import static com.atlassian.jira.issue.IssueFieldConstants.*
import groovy.transform.BaseScript

/*import org.apache.log4j.Level
log.setLevel(Level.DEBUG)
log.debug("--------------------This is to test Behaviours Logging----------------")*/
 
def assignee = getFieldById(ASSIGNEE)
def issueProject = getIssueContext().getProjectObject()

def issueTypeId = getFieldById(getFieldChanged()).getValue() as String
def issueTypeName = ComponentAccessor.getConstantsManager().getIssueType(issueTypeId).name

if (issueProject.key == "GL" && issueTypeName == "Idee")
{
    assignee.setFormValue("BuraccoP") //set user using the username
    assignee.setReadOnly(true)
}

else
{
    assignee.setFormValue("automatic")
    assignee.setReadOnly(false)
}

The script is linked to the field Issue Type. I do not use an initializer.

Thanks for any help.

PS: I didn't create a new topic since this issue here is exactly what I have. This way it's all in one place.

Suggest an answer

Log in or Sign up to answer