You're on your way to the next level! Join the Kudos program to earn points and save your progress.
Level 1: Seed
25 / 150 points
Next: Root
1 badge earned
Challenges come and go, but your rewards stay with you. Do more to earn more!
What goes around comes around! Share the love by gifting kudos to your peers.
Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!
Join now to unlock these features and more
The Atlassian Community can help you and your team get more value out of Atlassian products and practices.
Hi Guys,
Need your help, how to enable Bulk update existing issue using csv for users or suggest any other method like REST API or Scriprunner method which allow users to update existing issues every issue have different value.
Thanks
Hi @Vikrant Yadav,
For your requirement, you can try the sample working code below:-
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.search.SearchProvider
import com.atlassian.jira.issue.search.SearchQuery
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.jira.jql.parser.JqlQueryParser
import com.atlassian.jira.web.bean.PagerFilter
def jqlQueryParser = ComponentAccessor.getComponent(JqlQueryParser)
def searchProvider = ComponentAccessor.getComponent(SearchProvider)
def issueManager = ComponentAccessor.issueManager
def loggedInUser = ComponentAccessor.jiraAuthenticationContext.loggedInUser
def customFieldManager = ComponentAccessor.customFieldManager
def field1 = customFieldManager.getCustomFieldObjectsByName('Field 1').first()
def field2 = customFieldManager.getCustomFieldObjectsByName('Field 2').first()
final searchQuery = "project = MOCK order by key asc"
/**
* Path to the CSV file
*/
def file = new File("/home/ram/Downloads/content.csv")
def list = [] as ArrayList<Map>
/**
* Extract the value from the CSV file and add it to a List of Maps
*/
file.eachLine {
def column = it.split(',')
def mapInput = [:] as Map
mapInput.put('Key', column[0])
mapInput.put('Field1', column[1])
mapInput.put('Field2', column[2])
list.add(mapInput)
}
def query = jqlQueryParser.parseQuery(searchQuery)
def searchResults = searchProvider.search(SearchQuery.create(query, loggedInUser), PagerFilter.unlimitedFilter)
searchResults.results.each { documentIssue ->
def key = documentIssue.document.fields.find { it.name() == "key" }.stringValue()
def issue = issueManager.getIssueObject(key)
/**
* Iterate the List of maps and pass the value into the Custom Fields.
*/
list.each {data ->
if(data.get('Key') == issue.key) {
field1.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(field1), data.get('Field1')), new DefaultIssueChangeHolder())
field2.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(field2), data.get('Field2')), new DefaultIssueChangeHolder())
}
}
}
Please note, the sample working code above is not 100% exact to your environment. Hence, you will need to modify it accordingly.
What the example code above does is that it reads through the csv file and stores it into a List of Maps.
Next, it checks for the issues in the Project via JQL and passes the values from the List into the Issues of the project according to the issue's key.
Note: I have included the issue keys in the left column in the sample CSV file I used to filter the values from the List by the Issue key and pass it to the issues accordingly.
Below is a print screen of the configuration:-
Below is a print screen of the csv values I have tested with:-
Below is a print screen of the tickets with updated field values:-
I hope this helps to answer your question. :)
Thank you and Kind Regards,
Ram
Hi @Ram Kumar Aravindakshan _Adaptavist_ Thanks a lot as always for sharing the solution. But only JIRA admin have permission to access Script Console.
I want to allow users to bulk update existing issue. CSV file and path user will provide but only JIRA admin can run on script console.
Can we do one thing using script fragment put a button on issue screen like bulk update user only need to save file at path and click that button but i think that only works for fields which are added in script for any modifcation or minor change like adding they need to contact us for adding that field in script.
Thanks.
Vikrant Yadav
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Usually, you should have Global Permission when you want to do a bulk update in Jira.
Regarding the Script Fragment, you could try it, but you would also need to have a REST Endpoint setup that makes the bulk update.
There is an existing REST Endpoint example to make the bulk update in the Adaptavist library.
Once you have the REST Endpoint setup, you can follow the steps provided in the Adaptavist documentation to set up a web item.
Also, for the example provided in my previous comment, there is a more straightforward approach to trigger the bulk update using the console, i.e. without JQL. Below is the simplified code:-
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
def projectManager = ComponentAccessor.projectManager
def issueManager = ComponentAccessor.issueManager
def customFieldManager = ComponentAccessor.customFieldManager
def project = projectManager.getProjectByCurrentKey('MOCK')
def issues = issueManager.getIssueObjects(issueManager.getIssueIdsForProject(project.id))
def field1 = customFieldManager.getCustomFieldObjectsByName('Field 1').first()
def field2 = customFieldManager.getCustomFieldObjectsByName('Field 2').first()
/**
* Path to the CSV file
*/
def file = new File("/home/ram/Downloads/content.csv")
def list = [] as ArrayList<Map>
/**
* Extract the value from the CSV file and add it to a List of Maps
*/
file.eachLine {
def column = it.split(',')
def mapInput = [:] as Map
mapInput.put('Key', column[0])
mapInput.put('Field1', column[1])
mapInput.put('Field2', column[2])
list.add(mapInput)
}
issues.sort().each { issue ->
/**
* Iterate the List of maps and pass the value into the Custom Fields.
*/
list.each {data ->
if(data.get('Key') == issue.key) {
field1.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(field1), data.get('Field1')), new DefaultIssueChangeHolder())
field2.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(field2), data.get('Field2')), new DefaultIssueChangeHolder())
}
}
}
I hope this helps to answer your question. :)
Thank you and Kind Regards,
Ram
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks a lot @Ram Kumar Aravindakshan _Adaptavist_ . First solution works for me using Script Console.
Alternate solution i also provided to the users that use POSTMAN if possible for updating multiple issues in bulk. They only need to select data file (.csv) and run the Edit issue API. This will update all issues which are in csv file. This don't need any support from jira admin side.
Thanks Again! Have a Great week ahead.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Yadav -
Can you provide more details how you use POSTMAN?
Also, would it only work on the Cloud, or also on Data Center / Server? (I run v8.20).
thanks!
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.