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.
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.
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!!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.