Need to Set Summary Field using behavior

Manu Mishra February 7, 2021

Hello All,

I am looking for a way to concatenate the (Custom field Field Value Followed by Affect/s Version) as a Summary of the issue using Script runner Behavior. Although, part of the Script works but it adds '_null', so it seems not able to recognize the Affect/s Version values.

{code}

import com.atlassian.jira.component.ComponentAccessor
import com.onresolve.jira.groovy.user.FieldBehaviours
import groovy.transform.BaseScript
import static com.atlassian.jira.issue.IssueFieldConstants.SUMMARY
import static com.atlassian.jira.issue.IssueFieldConstants.AFFECTED_VERSIONS

@BaseScript FieldBehaviours fieldBehaviours

/**def AffectsVersion = getFieldByName("Affects Version/s").value**/
def AffectsVersion = getFieldByName(AFFECTED_VERSIONS).value
def Product = getFieldByName("Product Techno").value
def summary = getFieldById("summary")


summary.setFormValue("${Product}_${AffectsVersion}")

{code}

Please refer the attached screen shot.

null.png

Kindly let me know how can i fix this?

3 answers

2 accepted

0 votes
Answer accepted
mogavenasan
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 7, 2021

Hi @Manu Mishra,

There you go, tested with Behaviour and works:

import com.atlassian.jira.component.ComponentAccessor
import com.onresolve.jira.groovy.user.FieldBehaviours
import groovy.transform.BaseScript
import static com.atlassian.jira.issue.IssueFieldConstants.SUMMARY
import static com.atlassian.jira.issue.IssueFieldConstants.AFFECTED_VERSIONS

@BaseScript FieldBehaviours fieldBehaviours


/**def AffectsVersion = getFieldByName("Affects Version/s").value**/
def AffectsVersion = getFieldById("versions").value
def Product = getFieldByName("Product Techno").value
def summary = getFieldById("summary")

summary.setFormValue("${Product}_${AffectsVersion}")

I placed the same script on the custom field and the Affected Version field. 

Manu Mishra February 9, 2021

Thanks @mogavenasan It works at my side as well. However, how can i remove the braces around the affects version/s from summary. 

Also is it possible to validate the *Affects Version/s* from this project/type to accept only ONE version?

image.png

mogavenasan
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 9, 2021

Since you are using Behaviour, you can validate the number of elements in the list. If it's more than 1, clear the field value and prompt the user to enter only one value.

The braces around the value is because of the list. Try AffectsVersion[0].

0 votes
Answer accepted
Max Lim _Adaptavist_
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 7, 2021

The id for Affect/s Version is "versions". Also, you can simply use something like:

def versions = getFieldById("versions").value.toString()
def product = getFieldByName("Product Techno").value.toString()

getFieldById("summary").setFormValue("${product}_${versions}")
Manu Mishra February 9, 2021

Thanks @Max Lim _Adaptavist_ This is working perfectly. However, only concern is to remove the braces around the affect Version/s from jira summary.

image.png

Max Lim _Adaptavist_
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 9, 2021

There are many ways to do it, you can do it with string manipulation methods:

def versions = getFieldById("versions").value.toString().replace("[","").replace("]","")
def justText = getFieldByName("Just Text").value.toString()

getFieldById("summary").setFormValue("${justText}_${versions}")
Like Manu Mishra likes this
Manu Mishra February 15, 2021

Thanks @Max Lim _Adaptavist_ for your solution.

0 votes
Hana Kučerová
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
February 7, 2021

Hi @Manu Mishra ,

I think the main problem is Affects Version/s field returns list of versions, even if there's only one version stored.

I'm not sure, if it suitable for you to work only with the first one version, or you need to get all the versions and put the names together.

Please try...

Suggest an answer

Log in or Sign up to answer