how to append value updated in Single line text custom field to Multi line text custom field using Groovy script?

Manjunatha K R February 24, 2017

Hi,

Want to copy value updated in Single line text custom field (i,e Doc Version) to Multi line text custom field (i,e All Versions) using Groovy script?

//assuming this is a sigle line text field
def textFieldA = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Doc Version")
//assuming this is a Multi line text field
def textFieldB = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("All Versions")
 
issue.setCustomFieldValue(textFieldB, textFieldA) ==> is it appends values???
The "Doc Version" custom field value will get updated by issue assignee multiple times in my workflow @ different workflow transition steps.
I want to save all the version updated by assignee instead of overwriting it, I am trying to copy values into another Multi line text custom field i,e All Versions for Team's future reference.
Is this the right way or using one Multie line text custom field itself, we can try to preserve the previous values and get appended with latest version values using only one field itself? Please advice.   
  • Manju 

2 answers

1 accepted

1 vote
Answer accepted
Manjunatha K R February 28, 2017

Got it, the below script works as per my requirement.

'\n' between prev and current field value adds new line between 2 values. It works. Thanks.

import com.atlassian.jira.issue.Issue 
import com.atlassian.jira.issue.fields.CustomField 
import com.atlassian.jira.component.ComponentAccessor
 
CustomField textFieldB = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("SDD Document All Versions") 
 
issue.setCustomFieldValue(textFieldB, String.valueOf(issue.getCustomFieldValue(textFieldB)) + '\n' + String.valueOf(issue.getCustomFieldValue(ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("SDD Baselined Doc Version"))))
  • Manju
1 vote
Vasiliy Zverev
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 26, 2017

Try this code

import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.fields.CustomField

CustomField textFieldB = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("All Versions")

issue.setCustomFieldValue(textFieldB, issue.getCustomFieldValue(textFieldB) + issue.getCustomFieldValue(ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Doc Version")))
Manjunatha K R February 26, 2017

Thanks for your prompt response Vasiliy.

I am getting the below ERROR, when I tried to use the script you had suggested in Custom script post-function.

Static Type Checking - cannot find matching method

java.lang.Object#plus(java.lang.Object). Please check if declared type is right and if method exists

Possible solutions: use([Ljava.lang.Object;), is(java.lang.Object), use(java.lang.Class, groovy.lang.Closure), split(groovy.lang.Closure), wait(), find() @ line 8, column 39.

 

I am using JIRA Software 7.2.7 and SR version is 4.3.16

Manjunatha K R February 27, 2017

Hi Vasiliy,

Was trying alternate option of Using "Update Issue Custom Field" Add Post Function To Transition, updates an issue custom field to a given value. So I am trying to get the value from another custom field and trying to append it to the another 'Issue Custom Field' using this post function.

But I am unable to get the value of Custom Field Value from custom field id i,e customfield_10104

1) Issue Custom Field: SDD All Versions

2) Custom Field Value: customfield_10104 ==> this is another cusomt field id, from which I am trying to copy the value to 'SDD All Versions' custom field) here simply entering the ID of the option to be selected to get the value.

 

Append value:         If set, the given value will be appended to the field. Or if field supports multiple values, then the given value will be set without unsetting other ones.

Please make sure that the value you enter is valid for custom field its datatype and context configuration for the project using this workflow. Otherwise, the transition may fail at execution time. Additionally to enter text or numbers as value, you may use the following:

  • You may use macro '%%CURRENT_USER%%' to insert the function caller.
  • You may use macro '%%CURRENT_DATETIME%%' to insert the current date and time.
  • You may use macro '%%ADD_CURRENT_USER%%' to append the function caller. Obsolete please use append option instead with user macro above.
  • For Cascading Select fields, you may either use the value of the option to be selected, no need to add the parent for childs. Or simply enter the ID of the option to be selected.

 

  • Manju 
Vasiliy Zverev
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 27, 2017

Lets try this one:

import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.fields.CustomField

CustomField textFieldB = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("All Versions")

issue.setCustomFieldValue(textFieldB, String.valueOf(issue.getCustomFieldValue(textFieldB)) + String.valueOf(issue.getCustomFieldValue(ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Doc Version"))))
Manjunatha K R February 27, 2017

Thanks Vasiliy Zverev.

The shared script is able to append the values, but is it possible to copy values into "All Versions" from "Doc Version" into new line? As "All Versions" customfield is a Multi line Text.

So that reading values will be easier for JIRA Assignee's reference. Please advice how to do this in the shared script. Thanks.

Doc Version: 012345 (first time updated value)

Doc Version: 67890 (second time updated value)

 

Tushar July 12, 2018

The appended values started with "null" value. How to remove the "null" from the result

RPA-Cumu-Fulfilled-Res-Offshore:null[104294 - Bhandary,Venugopala, 104842 -                                                                       Shaikh,Anjumaara Mubarak]

rakesh rocckz April 11, 2019

@Manjunatha K R @Tushar @Vasiliy Zverev  at which place i should run this scrtipt?? i am running this in behavior am getting an error for the issue. the "issue" variable is undeclared?.please help me out where should i run this script?

Vasiliy Zverev
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.
April 18, 2019

This is for postfunction, condition or a validator. In these cases there is a variable issue is defined and represents cuurent issue.

To run it separatelly you should define this variable of class Issue or MutableIssue.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events