ScriptRunner Behaviour, automatically update field value based on another custom field

During issue creation, we make a custom field required, Regression Issue, in our JIRA workflow.  It's only required during creation.  We wanted to only force the requirement on new issues, not force all the previously created issues to update this field during edit.  Currently, we have a ScriptRunner Behaviors script to make other custom fields visible and/or required when certain values are select in the "Regression Issue" field. 

The problem arises with our SalesForce integration.  When users create new issues using the remote API.  The Regression Issue field doesn't register as required custom field. 

As a workaround, I was hoping to take advantage of the Behaviour script again to recognize a specific custom field, SalesForce ID, that's set during creation.  If a value is added (any value), then set "Regression Issue" select list to "No".  However, I can't seem to get this to happen.  I've also tried using certain user group as a criteria, but that's a no go too.

Is it possible to automatically force a field value change based on another field not being empty?  I've included my current Behavior script.

 

import com.onresolve.jira.groovy.user.FieldBehaviours
import groovy.transform.BaseScript

@BaseScript FieldBehaviours fieldBehaviours

def regressionIssueField = getFieldById(getFieldChanged())
def regressedVersionField = getFieldByName("Regressed from Version(s)")
def regressedBuildField = getFieldByName("Regressed from Build #")
def salesforceField = getFieldById(getFieldChanged())

String regressionIssueValue = regressionIssueField.getValue()
String salesforceValue = salesforceField.getValue()


if (salesforceValue) {
regressionIssueField.setRequired(false)
return
}

if (regressionIssueValue == "Yes") {
regressedVersionField.setHidden(false)
regressedBuildField.setHidden(false)
regressedVersionField.setRequired(true)
} else {
regressedVersionField.setRequired(false)
}

 

Thanks, Chuck

1 answer

This widget could not be displayed.

Unfortunately if your creating the issue through the REST API the behaviours are not applied. That is one of the limitations of behaviours explained here.

Your probably best off using a validator to make the field required which will still be applied when creating the issue via the REST API. If you want further customisation over the requiredness of the field you should consider writing a scripted validator.

OK.  I suspected that might be the case.  Thanks for confirming! 

Suggest an answer

Log in or Sign up to answer
Community showcase
Posted Tuesday in Jira

What modern development practices are at the heart of how your team delivers software?

Hey Community mates! Claire here from the Software Product Marketing team. We all know software development changes rapidly, and it's often tough to keep up. But from our research, we've found the h...

171 views 1 3
Join discussion

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you