Make a field mandatory based on another field

Alice June 30, 2021

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

1 vote
Answer accepted
Vikrant Yadav
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
July 1, 2021

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

Thanks

Vikrant Yadav
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
July 1, 2021

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
Alice July 2, 2021

Hi @Vikrant Yadav 

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

Vikrant Yadav
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
July 2, 2021

@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!

Shaikha Alketbi November 2, 2023

@Vikrant Yadav 

 

Can we have same script Make a field mandatory based on another field (dropdown list)

Vikrant Yadav
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
November 2, 2023

Hi @Shaikha alketbi 

Here is the sample script :- 

 

//Apply Scriptrunner behaviour on select list field

def team = getFieldByName("Accuracy") //select list field
def desc = getFieldById("description") //multi-line text field

log.debug("dropdown value" + team.getValue())

if (team.getValue() == "Satisfied") {
desc.setFormValue("Test Case 1")
}else if (team.getValue() == "Very Satisfied") {
desc.setFormValue("Test Case 2")
}else {
desc.setFormValue("")
}
Shaikha Alketbi November 2, 2023

Hi @Vikrant Yadav 

Thanks for your quick reply. 

What I am looking for I have list of Meeting if the user selects others, he should type the name of meeting on the text field and the text field become mandatory field

Shaikha Alketbi November 3, 2023

I used below script, but the field not marked as Mandatory once user select Others.

------------------------------------------------------------------------------------

 

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

@BaseScript FieldBehaviours behaviours

def Meeting = getFieldById('customFieldId=0000')
def Othertxt = getFieldById('customFieldId=0000')

log.debug("customFieldId=19301" + Meeting.getValue())

if(Meeting.toString().contains('Others') ) {
    Othertxt.setRequired(true)
} else {
    Othertxt.setRequired(false)
}
Vikrant Yadav
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
November 3, 2023

@Shaikha alketbi  What is the field type of "Meeting" field ? 

Shaikha Alketbi November 5, 2023

Meeting: drop down list 

Othertxt : single text field 

0 votes
Carlos Faddul
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
July 1, 2021

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. :)

Alice July 2, 2021

Hi @Carlos Faddul 

I am using Scriptrunner Behaviours. 

Carlos Faddul
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
July 2, 2021

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

Suggest an answer

Log in or Sign up to answer