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

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Make a field mandatory based on another field

Hello need help please
I have to make the system field due date mandatory only if the custom field delivery date desired is filled. Here is my script:

import com.atlassian.jira.component.ComponentAccessor
import com.onresolve.jira.groovy.user.FormField
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.CustomFieldManager

def issueManager = ComponentAccessor.getIssueManager()
def customFieldManager = ComponentAccessor.getCustomFieldManager()


def desired_delivery_date = customFieldManager.getCustomFieldObject("customfield_12303")
def issueObject = issue
def duedate = issueObject.getDueDate()

if ( desired_delivery_date != null){
      duedate.setRequired(true)
}

 

When I execute this script I get this error : 

groovy.lang.MissingMethodException: No signature of method: com.atlassian.jira.issue.fields.ImmutableCustomField.setRequired() is applicable for argument types: (Boolean) values: [false] at Script1288.run(Script1288.groovy:21)

 

Thanks for your help

2 answers

1 accepted

0 votes
Answer accepted

Hi @Alice  Are you trying to make due date mandatory using Sripted Validator or using ScriptRunner Behaviour ?

Thanks

Hi @Alice  Apply Below Script in ScriptRunner >> Behaviours > in delivery date desired field server side script to make due date mandatory when delivery date desired is not empty.

 

import com.onresolve.jira.groovy.user.FieldBehaviours
import groovy.transform.BaseScript
import com.atlassian.jira.component.ComponentAccessor
import java.sql.Timestamp

@BaseScript FieldBehaviours fieldBehaviours

def formfield = getFieldById("customfield_35350")
def duedate = getFieldById("duedate")

def releaseDate = formfield.value as Date


if (releaseDate){
duedate.setRequired(true)
} else if (!releaseDate) {
duedate.setRequired(false)
}

 Kindly replace field id 35350 with your custom field id.

Thanks

VY

Like Carlos Faddul likes this

Hi @Vikrant Yadav 

I am using Scriptrunner Behaviours. Thanks for the script I test.

@Alice  In Behaviour above script works fine. 

kindly accept the answer if this resolves your issue!! It helps other user to find right solution who is having same query.

Thanks!

Hi @Alice , do you have the add-on JMWE or Script Runner ?

 

If you have JMWE, you can use validators with the required field based on condition. :)

Hi @Carlos Faddul 

I am using Scriptrunner Behaviours. 

I believe the @Vikrant Yadav  resolved the problem already :)

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Jira

⏰ Day in the life of a Jira Admin!

Hello Community! We thoroughly enjoyed this just-for-fun conversation in the Jira Admin Group about what it's like to be a Jira Admin. For #JiraJuly, our talented designers created these graphics t...

706 views 2 21
Read article

Community Events

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

Find an event

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

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you