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

2 votes

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 Join to answer
Community showcase
Sarah Schuster
Posted Jan 29, 2018 in Jira

What are common themes you've seen across successful & failed Jira Software implementations?

Hey everyone! My name is Sarah Schuster, and I'm a Customer Success Manager in Atlassian specializing in Jira Software Cloud. Over the next few weeks I will be posting discussion topics (8 total) to ...

2,864 views 12 18
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
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot