Copy custom field value to comments

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

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 ;)

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);
}

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

 

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.

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?

Any comments guys?

Thanks in advance for your help

Rahul

Suggest an answer

Log in or Sign up to answer
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Julia Dillon
Posted Apr 17, 2018 in Jira

Tell us how your team runs on Jira!

Hey Atlassian Community! Today we are launching a bunch of customer stories about the amazing work teams, like Dropbox and Twilio, are doing with Jira. You can check out the stories here. The thi...

807 views 2 19
Join discussion

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you