Hi,
Currently, I am using the below script to hide/show the fields based on the Issue Summary and it is working fine.
import com.onresolve.jira.groovy.user.FieldBehavioursimport groovy.transform.BaseScript@BaseScript FieldBehaviours fieldBehaviours def summ = getFieldById('summary').value as Stringdef poNumber = getFieldById('customfield_29016') //PO NumberpoNumber.setHidden(true)
if (summ == 'Receiving/Scan/Update AMDB'){ poNumber.setHidden(false) poNumber.setRequired(true)}
Hi @Manoj Kumar Gangwar
You must create a Server-Side Behaviour for the Summary field for your requirement.
This is required because the Behaviour is expected to trigger when the Summary field changes.
You will also need to modify your code to:-
import com.onresolve.jira.groovy.user.FieldBehavioursimport groovy.transform.BaseScript@BaseScriptFieldBehaviours fieldBehaviourdef summ = getFieldById(fieldChanged).value as Stringdef poNumber = getFieldById('customfield_29016') //PO NumberpoNumber.setHidden(true) if (summ == 'Receiving/Scan/Update AMDB'){ poNumber.setHidden(false) poNumber.setRequired(true)}
You need to use the fieldChanged when declaring the Summary field instead of the field's id, i.e. 'summary' as shown below, to monitor if the value for the Summary field has been updated to ensure the Behaviour is triggered correctly.
def summ = getFieldById(fieldChanged).value as String
Below is the sample code that I have tested in my environment:-
import com.onresolve.jira.groovy.user.FieldBehavioursimport groovy.transform.BaseScript@BaseScript FieldBehaviours behavioursdef summary = getFieldById(fieldChanged).value as Stringdef sampleList = getFieldByName('Sample List')sampleList.required = falsesampleList.hidden = trueif (summary == 'Test 123') { sampleList.required = true sampleList.hidden = false}
Please note that the sample working code above is not 100% exact to your environment. Hence, you will need to make the required modifications.
Below is a screenshot of the Server-Side Behaviour configuration for the Summary field:-
Below are a couple of test screenshots for your reference:-
1. By default, when the Create screen loads, the Sample List is hidden, as shown in the screenshot, because the Summary is empty, i.e. does not match the condition that has been set in the Behaviour
2. Once the Summary is updated to Test 123, i.e. it meets the condition set in the Server-Side Behaviour, the Sample List is visible and set to required.
3. If the Summary is updated to something other than Test 123, as expected, the Sample List field is hidden and set to not required, as shown in the screenshot below:-
I hope this helps to solve your question. :-)
Thank you and Kind regards,
Ram
Hi @Ram Kumar Aravindakshan _Adaptavist_ ,
Thanks for your reply. Is there any way to use summary as a wildcard so If the issue have a particular word then behavior works to show the field on screen.
In your last comment, you asked:-
Is there any way to use summary as a wildcard so If the issue have a particular word then behavior works to show the field on screen.
To answer your question, yes, this is doable. For the if/else condition to do a wildcard check, you will need to change it from:-
if (summary == 'Test 123') {......}
to
if (summary.contains('Test 123')) { ... ...}
Thanks for your quick reply. It resolved my issue.
It looks like you're new here. Sign in or register to get started.