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

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

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

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.
Jul 01, 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.
Jul 01, 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

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.
Jul 02, 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!

@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.
Nov 02, 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("")
}

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

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.
Nov 03, 2023

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

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.
Jul 01, 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. :)

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.
Jul 02, 2021

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

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events