Forums

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

Make a "Custom Field Required" based on specific values of a system Summary Field.

Tanwa Arewa
Contributor
September 13, 2021

I have two questions Please!

1. I normally use ScriptRunner defaults scripts, but I need to make a field required based on a specific summary.  I  have tried the following script but it's not working. When transitioning to Done, set the "New ToLID" custom field if the issue summary field is as follows:  "New ToLID assigned.  The issue is a subtask.   I am setting this in the Behaviours. Pls advise 

if ("Done".equals(getActionName())) {
log.error("Behaviour start on screen Done issue")
def targetField = getFieldByName("New ToLID")
targetField.setRequired(false)
if (issue.getSummary().contains("New ToLID assigned"))

targetField.setRequired(true)
}
}

2. I tried to use the ScriptRunner Validator field required in the workflow, but when i get to the select field option it has no option see screenshot below, even those there are a bunch of custiom fields configured on the data center server.  On the other hand, i can see the custome fields when using conditions, but when set it makes the transition button disappear.  Please advise.  Many Thanks in Advance 

Capture1.PNG

2 answers

1 accepted

0 votes
Answer accepted
Ram Kumar Aravindakshan _Adaptavist_
Community Champion
September 13, 2021

Hi @Tanwa Arewa

For your requirement, you don't need to invoke the underlyingIssue in the Behaviour. You can do this:-

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

@BaseScript FieldBehaviours behaviours
def summary = getFieldById(fieldChanged)
def sampleField = getFieldByName('Sample Field')
sampleField.required = false

if(summary.toString().contains('Sample Field') && actionName == 'Done') {
sampleField.required = true
}

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

When the issue transitions to Done and the transition screen appears, the Sample Field text field will be mandatory if the Summary has the value Sample Field in it.

Below are a few test print screens for your reference:-

1) The summary currently is just Test

image1.png

2) When the issue transition's to Done, the Sample Field is not set to mandatory.

image2.png

3) Once the field name, i.e. Sample Field, is included, the Sample Field text field is mandatory.

image3.png

4) Now, if you try to click on the Done button without entering any values into the Sample Field, an Error message is returned, as displayed below.

image4.png

I hope this helps to answer your question. :)

Thank you and Kind Regards,

Ram

Tanwa Arewa
Contributor
September 14, 2021

Thank You so much @Ram Kumar Aravindakshan _Adaptavist_ for the prompt solution.  I have used the code and it works perfectly.  Very Much Appreciated.

1 vote
Leo
Community Champion
September 13, 2021

Hi @Tanwa Arewa,

If I understood correctly you want to limit the behaviour done transition

how about below code. this can be a initializer script

if(fieldScreen.name == "Transition screen name"){
if(issue.summary.contains("required string")){
getFieldByName("Field Name").setRequired(true)
}
}

 

BR,

Leo

Tanwa Arewa
Contributor
September 14, 2021

Thank You @Leo for your prompt response.  Very much Appreciated. I used the Ram's code 

Suggest an answer

Log in or Sign up to answer