Populate Summary field, taking Dynamic 'Affect version' value created during Issue creation

Ayushi Saxena March 18, 2021

Hello All,

My Requirement is to Auto-Populate Summary field with concatenation of a Custom Field &  Affect version field, I have achieved it with Script runner Behavior. Also, have allowed only one affect version selection.

Now part of the Script works well when Existing Affect version is selected but If NEW AFFECT VERSION is created during Issue creation, it adds 'null' instead of version, so it seems not able to recognize New Affect/s Version value.

Behavior added -> Field 'Affect Version' selected -> Below code is written in server side script section

{code}

-----------------

def OneAffectsVersion = getFieldById("versions")
Object AffectsVersion = getFieldById("versions").getValue();
String affectedVersion = null;
if (AffectsVersion instanceof ArrayList) {

//To Fetch Version value without []
if (AffectsVersion.size() > 0) {
affectedVersion = AffectsVersion.get(0) as String;
}

//To Allow only One affect version selection
if (AffectsVersion.size() > 1) {
OneAffectsVersion.setError("Build revisions may only have one affects version-New");
}
else OneAffectsVersion.clearError()
}


def CustomField= getFieldByName("CustomField").value
def summary = getFieldById("summary")
summary.setHidden(true)
summary.setFormValue("${CustomField} ${affectedVersion}")

------------------

Kindly share what is going wrong or needs to be added to Fetch dynamic New Affect version created

Let me know if I can explain more.

2 answers

1 accepted

1 vote
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.
March 23, 2021

I have made some tests. The newly filled to-be-created version can't be retrieved with Behaviour.

Looking at your script, your use case can probably also be achieved with post-function.

1. Navigate Project Settings > Workflows > edit the appropriate workflow > click on Create transition > Post Functions > Add post function > Script Post-Function [ScriptRunner] > Custom script post-function.

2. Paste in the following script:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.issue.MutableIssue

def issueManager = ComponentAccessor.getIssueManager()
def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def customField = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectsByName("CustomField").first()
def customFieldValue = issue.getCustomFieldValue(customField)
def affectedVersion = issue.getAffectedVersions().first()

issue.setSummary("${customFieldValue} ${affectedVersion}")
issueManager.updateIssue(user, issue, EventDispatchOption.ISSUE_UPDATED, true)

3. Modify the order of this post-function after "Creates the issue originally.".

4. Publish the changes.

Ayushi Saxena March 24, 2021

Thanks @Max Lim _Adaptavist_ It is working as required, however, it will not work on Issue Edit case so any way in which it can be implemented during Edit issue as well (Issue is edited, selected Affect version is removed and new version added so Summary to be changed) .Also, have to add Allow only one affect version selection.

Thanks again for your time!!

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.
March 24, 2021

I didn't think you want to edit issue.


You can implement the same script as a listener on Issue Created and Issue Updated events:

1. Navigate ScriptRunner > Listeners > Create Listeners > Custom Listener.

2. Choose appropriate project, and choose Issue Created and Issue Updated events.

3. Under script: replace "issue" with "event.issue" in script above.

0 votes
Ayushi Saxena March 23, 2021

@Max Lim _Adaptavist_ / @Ravi Sagar _Sparxsys_ : Can you kindly guide

Suggest an answer

Log in or Sign up to answer