Copy custom field value to comments

Rahul Aich [Nagra]
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 2, 2014

Hi

I want to copy value from a custom field over to comments with prefix custom field name and followed by the value.

e.g. say I have a custom field Driver Version with a value of say 1.2.3. I want to copy in the comments this text Driver Version: 1.2.3.

I want to this task in bulk (i.e update 2000 issues at one go).

Is this possible?

Rahul

5 answers

1 vote
NeilW February 24, 2016

Thanks.  This was helpful.  This is the script I ended up with.  I was hoping to parameterize it but never quite got that far.

// For all issues with a value for specified custom field, append CustomFieldName: CustomFieldValue to the description and as a comment.
// Set both name of custom field and ID before running this script.
// Confirm correct operation by checking at least one issue.
// This is used to avoid losing data when deleting a custom field.
string fieldName = "My Custom Field Name";
string curruser = currentUser();
string[] keys = selectIssues("\"" + fieldName + "\" is not EMPTY");
for (string k in keys) 
{
    // Get field value
    string fieldValue = %k%.customfield_11514;
    /* The code below does not work for field names with spaces in them, so use the line above
    string[] fieldValues = getIssueFields(k);
    string fieldValue = fieldValues[fieldName]; */
    
    // Append custom field name and value to description field
    %k%.description = %k%.description + "\r\n\r\n" + fieldName + ": " + fieldValue;
    
    // Append custom field name and value as a comment
    addComment(k, curruser, fieldName + ": " + fieldValue);
}
J May 12, 2016

HI Nell,

 

Can I know where should I implement this code like post function?

I want to implement on bulk update, is it possible?

Can I know how to implement because i am new this scriptrunner? What are the requirements to implement this?

Thanks,

Jana

 

1 vote
Radu Dumitriu
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 3, 2014

Obviously it is possible.

1. Install JJupin

2. Add the SIL runner on the dashboard and run the following script

string curruser = currentUser();

string [] keys = selectIssues("project = PRJ ..... bla bla");

for(string k in keys) {

addComment(k, curruser, "Driver version:" + customfield_54321);

}

3. Uninstall JJupin

Note: I did not tested the script, this is just the example, and you anyway need to put a proper JQL and customfieldId into it.

Ah, ... and JJupin has a nice feature, it shows where CF's are used. You may want to try that too ;)

1 vote
Rahul Aich [Nagra]
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 2, 2014

Hi Luther

This is just an example, the need behind this is that we are trying to cut down on number of custom fields.

Once we copy the data to comments we are going to delete the custom field.

0 votes
Rahul Aich [Nagra]
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 3, 2014

Any comments guys?

Thanks in advance for your help

Rahul

0 votes
Luther Hargrove
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 2, 2014

Can I ask why you would do this? Since Driver Version is already being tracked on the issues, why would you put in a comment with the exact same data?

Suggest an answer

Log in or Sign up to answer