Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Next challenges

Recent achievements

  • Global
  • Personal

Recognition

  • Give kudos
  • Received
  • Given

Leaderboard

  • Global

Trophy case

Kudos (beta program)

Kudos logo

You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.

View group

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Need to Set Summary Field using behavior

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

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}")

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

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

Thanks @Max Lim _Adaptavist_ for your solution.

0 votes
Answer accepted

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. 

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

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
Hana Kučerová Community Leader Feb 07, 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
TAGS

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you