Make field required when it is not set to ReadOnly for specific transition

Preeti Yadav August 25, 2022

I have a Field called "Domain" - need to make it required when it is not set to ReadOnly.

For specific workflow transition. Am trying to do this using "Field(s) required validator".

Am attaching the Screenshot for the same. Am not knowing if am doing the right way. Please guide me.Screenshot 2022-08-26 105023.jpg

1 answer

1 accepted

3 votes
Answer accepted
Ram Kumar Aravindakshan _Adaptavist_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
August 27, 2022

Hi @Preeti Yadav

Your approach will not work because the method setReadOnly is only usable in the Behaviour and not in Validators.

For your requirement, why not just add a transition screen? And for that transition screen, you can use the Behaviour to set the field to required and editable. Using this approach, you can use Behaviour to validate to ensure that the value of the field is added.

Below is a sample code for your reference:-

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

@BaseScript FieldBehaviours behaviours
def sampleTextField = getFieldById(fieldChanged)

sampleTextField.required = false
sampleTextField.readOnly = true

if (actionName == 'Done') {
sampleTextField.required = true
sampleTextField.readOnly = false
}

Please note that the sample code provided is not 100% exact to your environment. Hence, you will need to make the required modifications. 

Below is a screenshot of the Behaviour configuration:-

behaviour_config.png

Also, I have included a few test screens for your reference.

1. First, when creating a new issue, no value is added to the Sample Text Field, as shown below:-

image1.png

2. Once the issue has been created, it will be transitioned to the Done status.

image2.png

3. Once the Done button is clicked, the Done transition screen appears, and in it, the Sample Text Field is added. Now, the field is editable and is set to required, as shown below:-

image3.png

4. If I try to close the issue without adding any value to the field in the transition screen, as expected, the validator returns an error message saying that the value for the field is required, as shown below:-

image4.png

5. Once the value is added for the Sample Text Field on the transition screen, the issue can be transitioned to the Done status. Below you can see that the issue has transitioned, and a value has been added for the Sample Text Field.

image5.png

 

I hope this helps to solve your question. :)

Thank you and Kind regards,

Ram

Preeti Yadav August 28, 2022

Hi @Ram Kumar Aravindakshan _Adaptavist_ 

Thanks for suggesting this approach. Working fine! 

Suggest an answer

Log in or Sign up to answer