Forums

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

Scriprunner Behavior to show fields based on Summary

Manoj Gangwar
Community Champion
August 7, 2023

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.FieldBehaviours
import groovy.transform.BaseScript
@BaseScript FieldBehaviours fieldBehaviours

 

def summ = getFieldById('summary').value as String
def poNumber = getFieldById('customfield_29016') //PO Number
poNumber.setHidden(true)
 if (summ == 'Receiving/Scan/Update AMDB'){
     poNumber.setHidden(false)
     poNumber.setRequired(true)
}
Now I have updated the Issue Summary from 'Receiving/Scan/Update AMDB' to 
'{{issue.customfield_31622}} - Receiving/Scan/Update AMDB'(basically we copied some fields value to Summary fields) but after that behavior stopped working. I tried to update in script like this-> '{{issue.customfield_31622}} - Receiving/Scan/Update AMDB' but it didn't work.
Could you please suggest how can I achieve this?

1 answer

1 accepted

Suggest an answer

Log in or Sign up to answer
1 vote
Answer accepted
Ram Kumar Aravindakshan _Adaptavist_
Community Champion
August 7, 2023

Hi @Manoj 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.FieldBehaviours
import groovy.transform.BaseScript

@BaseScript FieldBehaviours fieldBehaviour

def summ = getFieldById(fieldChanged).value as String
def poNumber = getFieldById('customfield_29016') //PO Number

poNumber.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.FieldBehaviours
import groovy.transform.BaseScript

@BaseScript FieldBehaviours behaviours
def summary = getFieldById(fieldChanged).value as String
def sampleList = getFieldByName('Sample List')

sampleList.required = false
sampleList.hidden = true

if (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:-

behaviour_config.png

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

test1.png

 

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.test2.png

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:-test3.png

I hope this helps to solve your question. :-)

Thank you and Kind regards,

Ram

Manoj Gangwar
Community Champion
August 7, 2023

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.

Ram Kumar Aravindakshan _Adaptavist_
Community Champion
August 7, 2023

Hi @Manoj Gangwar

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')) {
...
...
}

I hope this helps to solve your question. :-)

Thank you and Kind regards,

Ram

Like Manoj Gangwar likes this
Manoj Gangwar
Community Champion
August 7, 2023

Thanks for your quick reply. It resolved my issue.

TAGS
AUG Leaders

Atlassian Community Events