Field not updating in ScriptRunner Behaviour after required field error

Jason Adam
Contributor
May 3, 2018

I have a Behaviour script that sets the selected values for one custom field (Required Reviewers) based on the selection from another single select list (Mission Phase).  The field that the behaviour is set on (Mission Phase) is marked as required.

The scripts works perfectly fine normally, unless I try to create an issue without selecting a value in the required field (defaults to None).  When I do this, I get the normal error saying Mission Phase is Required, but selecting values in this field no longer update the selected values in the Required Reviewers field.

When I put log messages in the script, everything is being called correctly, it's getting the correct values from the fields, etc.  And I briefly see a little wheel at the bottom of the Create screen, but nothing else.  I get no errors in the log.

Is there something I need to add to the script to force this?  Or is there a reason why when a Create screen gets these required errors a behaviour would stop updating other fields correctly?

2 answers

1 vote
JohnsonHoward
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.
May 4, 2018

Hi Jason.

Can I take a look at the script?

If you are setting the value of a select list I assume you are using the options manager to get the option by passing it the fieldConfig. My suspicion is that it may be something to do with this. 

Thanks

Johnson Howard (Adaptavist)

Jason Adam
Contributor
May 4, 2018

Sure, here it is

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.customfields.option.Option

class MissionPhaseDefault extends com.onresolve.jira.groovy.user.FieldBehaviours
{
    def commList = ['SI Lead', 'WF Lead', 'MSE', 'MOM', 'OC', 'bMOC']
    def normList = ['OC', 'MOM']
    def tsrList = ['TLC']

    def run()
    {
        def missionValue = getFieldByName("Mission Phase").getValue()
        def list = null
    
  if(issueContext.issueType.name = "Timeline Scheduling Request")
        {
            list = tsrList
        }
        else if(missionValue.equals("Normal Ops"))
        {
            list = commList
        }
        else if(missionValue.equals("Normal Ops"))
        {
           list = norList
        }


        def reqField = getFieldByName("Required Reviewers")
        def reqCustom = ComponentAccessor.getCustomFieldManager().getCustomFieldObject(reqField.getFieldId())
        def config = reqCustom.getRelevantConfig(getIssueContext())
        def options = ComponentAccessor.getOptionsManager().getOptions(config)
        def optionsToSelect = options.findAll{it.value in list}
        reqField.setFormValue(optionsToSelect*.optionId)
    }
}
JohnsonHoward
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.
May 4, 2018

And is the field set as required in the field configuration or by another behaviour?

JohnsonHoward
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.
May 4, 2018

Hi Jason,

It turns out that this was actually a previously known issue and has actually been fixed in the latest version. If you update your ScriptRunner version then this issue should not persist.

Let me know if you still have the issue after the upgrade.

Thanks 
Johnson Howard (Adaptavist)

Jason Adam
Contributor
May 4, 2018

It was marked as required through the normal field configuration, not a behaviour.

Awesome, I'll download the latest and see how it behaves and will let you know.  Thanks!

Jason Adam
Contributor
May 6, 2018

That seems to have done the trick, thanks!

JohnsonHoward
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.
May 8, 2018

Great, would you mind marking this answer as Accepted please?

0 votes
JohnsonHoward
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.
May 10, 2018

Can this answer be marked as accepted please Jason?

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events