Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

How to set a custom text field(multi line) as required in a post function

Raj Alagappan
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
November 9, 2021

I have a custom text field (Release Note description) which must be set as required field when issue is resolved and if another custom field (Release Note) value is "Required". Below is the current script I wrote as a post function on issue resolution and currently it shows error on releaseNoteDescField.setRequired(true)

import com.onresolve.jira.groovy.user.FieldBehaviours
import groovy.transform.BaseScript
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.user.util.UserManager

def customFieldManager = ComponentAccessor.getCustomFieldManager()
def releaseNoteField = customFieldManager.getCustomFieldObject("customfield_xxxx")
def releaseNote = issue.getCustomFieldValue(releaseNoteField)
def releaseNoteDescField = customFieldManager.getCustomFieldObject("customfield_xxxx")
def releaseNoteDescription = issue.getCustomFieldValue(releaseNoteDescField)

if (releaseNote == "Required") {
releaseNoteDescField.setRequired(true)
}

1 answer

0 votes
Martin Bayer _MoroSystems_ s_r_o__
Community Champion
November 10, 2021

Hi @Raj Alagappan , welcome on the community. It seems to me you are mixing more things together

  • postfunction
  • behaviours (releaseNoteDescField.setRequired(true))
  • validators

You definitelly cannot use postfunction to validate anything. Postfunction just executes some code or operation after the information on transition are validated. So you can use

  • Validators - can be configured on workflow transitions (similarly to postfunctions). It validates the state of the issue and if it fails, transition is not executed
  • Behaviours - you can use it to dynamically set field as required on the transition screen (if some condition pass, field is marked as required right on the screen). You can get more information + examples here: https://docs.adaptavist.com/sr4js/latest/features/behaviours

 

Hope, it helped. And if not, feel free to ask..

Raj Alagappan
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
November 10, 2021

Hi @Martin Bayer _MoroSystems_ s_r_o__  Thanks a lot for the response. My requirement is to validate a custom field value and based on it set another custom field as required. What would be the best solution (validator, behavior or post function) for my problem? I guess I cannot use validator as it can validate but not set custom fields. The reason I did not go with behaviors is I thought it is not efficient as I want this to happen only when issue is Resolved but setting up a behavior will get triggered irrespective of the workflow and not just when issue is Resolved. But behavior is the only way to go here I can setup a behavior and add another condition to check if issue status = "Resolved"

Martin Bayer _MoroSystems_ s_r_o__
Community Champion
November 11, 2021

Hi @Raj Alagappan, if you use validator, the flow will be

  1. user set Release Note to "Required"
  2. user presses OK
  3. Jira displays Validator error "Release Note Description is mandatory"
  4. user set some value for Release Note Descriptio
  5. user presses OK
  6. Jira saves the information and transitions issue to Resolved

You can use Behaviour ofcourse, it can be configured for single transition (action) as described here: https://docs.adaptavist.com/sr4js/latest/features/behaviours/behaviours-examples/require-comment-for-action

Selection_453.png

Suggest an answer

Log in or Sign up to answer