Forums

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

set value of a version picker customfield with scriptrunner

wajih zouaoui
Contributor
August 18, 2020

Hi,

i would like if someone help to create a script listner for updating parent issue and specially a customfield with a Version type named "Target Version/s".

We have a parent issue with Outwards linked issues.

We need to get all the TargetVersion/s from the linked issues and map it to the same Customfield into the parent issue.

Eg:

Target Version/s value for linked issue 1 = 4.1

Target Version/s value for linked issue 2 = 5.1

 

Target Version/s value for the parent issue = 4.1 5.1

 

Can help me please ?

 

Thanks in adavance.

 

I've tried to create something but i"m not good in this point:

 

import com.atlassian.jira.issue.MutableIssue;
import com.atlassian.jira.issue.IssueManager;
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.link.IssueLink;
///
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.bc.issue.IssueService;
import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.bc.issue.search.SearchService;
import com.atlassian.jira.user.util.UserManager;
import com.atlassian.jira.user.ApplicationUser;
//import com.atlassian.crowd.embedded.api.User;
import com.atlassian.jira.issue.search.SearchResults;
import com.atlassian.jira.web.bean.PagerFilter;
import com.atlassian.jira.bc.issue.IssueService.DeleteValidationResult;
import com.atlassian.jira.issue.IssueManager;
import com.atlassian.jira.event.type.EventDispatchOption;
import com.atlassian.jira.issue.CustomFieldManager;
import com.atlassian.jira.issue.fields.CustomField;
import org.apache.log4j.Category;
import com.atlassian.jira.issue.issuetype.IssueType;
import com.atlassian.jira.component.ComponentAccessor;
import javax.mail.Multipart;
import com.atlassian.mail.Email;
import com.atlassian.mail.server.MailServerManager;
import com.atlassian.mail.server.SMTPMailServer;
import javax.mail.internet.MimeMultipart;
import javax.mail.internet.MimeBodyPart;
import javax.mail.util.ByteArrayDataSource;
import javax.activation.DataSource;
import javax.activation.DataHandler;
import com.atlassian.jira.project.version.Version;
import groovy.xml.XmlUtil;
import com.atlassian.jira.project.version.VersionManager;
import com.atlassian.jira.issue.MutableIssue;

IssueManager im = ComponentAccessor.getIssueManager();
MutableIssue issue = im.getIssueObject("NXDH-20861");




def links = ComponentAccessor.getIssueLinkManager().getOutwardLinks(issue.getId());


def output = "" ;




for ( l in links) {

output = output + " " + l.getDestinationObject() ;
log.debug ("Le ticket parent est: " + output);

}


def output1 = output.split() as List




for (l in output1) {

def MutableIssue str = im.getIssueObject(l)
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def cField = customFieldManager.getCustomFieldObject("customfield_10243")
def cFieldValue = str.getCustomFieldValue(cField)

def Allcdfv = cFieldValue

issue.setCustomFieldValue(cField,Allcdfv)
log.debug ("Le target version de la fiche : " + issue + " a été mise à jour à: " + cFieldValue );

}

1 answer

1 accepted

0 votes
Answer accepted
Nic Brough -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.
August 18, 2020

I think you could use these two to do it:

The first script shows you how to get a value from a field so it can be replicated into the same field on to a sub-task when the sub-task is created. 

The important part of this is to look at how a value is handled in variables.  When you look at a version field, you will find its data is a collection of version objects, not a string or label.  When you want to populate your custom version field, it will be expecting the same thing - a version object or collection of them.

https://library.adaptavist.com/entity/copy-field-value-from-parent-issue-to-sub-task-upon-creation

The second one is showing you how to set most custom field types - follow it through for "version picker"

https://library.adaptavist.com/entity/update-the-value-of-custom-fields-through-the-script-console

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
SERVER
TAGS
atlassian, jira service management, jsm webinar, ai in jsm, opsgenie integration, incident management, virtual agent, atlassian intelligence, ai-powered service desk, it operations, atlassian learning, service management webinar, team '25 recap

What’s new in Jira Service Management 🤔

Discover how Atlassian is revolutionizing service management with cutting-edge solutions for AI-powered support, HR Service Management, or DevOps connectivity.

Register here ⬇️
AUG Leaders

Atlassian Community Events