Make field mandatory only when changing value from group picker

Prashant Mali March 24, 2018

Requirement :

on edit screen

when I changed the value of a group picker

comment field should get madatory

 

Below is a behavior script which I implemented

import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.component.ComponentAccessor

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

import com.onresolve.jira.groovy.user.FormField

@BaseScript 

FieldBehaviours fieldBehaviours

def commentField = getFieldById("comment")def grouppickerfield = getFieldById("customfield_54400")
FormField field = getFieldById(getFieldChanged())

//log.error "g---------------"+commentField.getValue()+ "test:"+grouppickerfield.getValue();

log.error "<<<"+field.getFormValue()

if (field.getFormValue())

{   

log.error ">>>in if condition"       commentField.setRequired(true)

}

result :

It works for first time when I changed value. but second time, It is not working

 

 

 

 

1 answer

0 votes
Fabio Racobaldo _Herzum_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
March 24, 2018

Hi Prashant ,

probably you need to set commentField as not mandatory at the start of your code 

{code}

import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.component.ComponentAccessor

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

import com.onresolve.jira.groovy.user.FormField

...

commentField.setRequired(false);

...

@BaseScript 

FieldBehaviours fieldBehaviours

def commentField = getFieldById("comment")def grouppickerfield = getFieldById("customfield_54400")
FormField field = getFieldById(getFieldChanged())

//log.error "g---------------"+commentField.getValue()+ "test:"+grouppickerfield.getValue();

log.error "<<<"+field.getFormValue()

if (field.getFormValue())

{   

log.error ">>>in if condition"       commentField.setRequired(true)

}

{code}

Prashant Mali March 24, 2018

yup. I have the same configuration here. The comment field is not mandatory at startup. 

Suggest an answer

Log in or Sign up to answer