We would like to copy the date from 'Start Date' to 'Begin Date' in all the issues that are not in 'Done' status. Is there any script achieve this task?
Hi Sai,I would say the solution would depend heavily on how you want this to occur.The different ways this could be triggered
If you could specify in better detail how you want this to run it would probably be easier to assist you.Regards
Hi Jeff,
Thank you for your response, we would like to run it manually by Scriptrunner one time for now. Please let me know if there is a script.
Hi.I wrote a script for you.I haven't tested it but please give it a try and Get back to me with the results.Please make sure you first test it on a staging environment.I cannot remember if scriptrunner supports outputs so you might have to tinker with the returns to see the results and such.I always run my scripts in Riada Insights script console, I prefer it.
import com.atlassian.jira.user.util.UserUtilimport com.atlassian.jira.component.ComponentAccessor;import com.atlassian.jira.bc.issue.search.SearchServiceimport com.atlassian.jira.web.bean.PagerFilterimport com.atlassian.jira.issue.Issueimport com.atlassian.jira.issue.IssueManagerimport com.atlassian.jira.issue.MutableIssueimport com.atlassian.jira.issue.fields.CustomField;import com.atlassian.jira.event.type.EventDispatchOption;import com.atlassian.jira.component.ComponentAccessor;import com.atlassian.jira.util.ImportUtils;import com.atlassian.jira.issue.index.IssueIndexingService/************************************///SCRIPT SETS ALL ENTERED KEYS OR SEARCH MATCH TO DO NOT SEND//If you enter keys (ABCD-1234) enter them as "ABCD-1","ABCD-2" etc.def keys = [];//if you want to use JQL to find the issues please enter it here.// This may not support some plugin functionality (eg issueFunction).String jql = '';//if you're using keys to pick issues, please set this to falseboolean doSearch = true;// when running this for the first time, set this to true.//this will make it output the amount of issues it detected.boolean checkNumberAffected = true;//user to run the searches asdef username = "";//field to take the value fromdef sourceFieldId = 12345;//field to set the value indef targetFieldId = 12345;/***********************************///to find this go to cog>issues>customfields>cog. and then hover over configure and check id in urldef targetField = ComponentAccessor.getCustomFieldManager().getCustomFieldObject(targetFieldId)def sourceField = ComponentAccessor.getCustomFieldManager().getCustomFieldObject(sourceFieldId)UserUtil userUtil = ComponentAccessor.getUserUtil()IssueManager issueManager = ComponentAccessor.getIssueManager()SearchService searchService = ComponentAccessor.getComponent(SearchService.class)def user = userUtil.getUserObject(username)//ApplicationUser.getDirectoryUser()ArrayList<Issue> issues = new ArrayList<>();if(doSearch) { SearchService.ParseResult parseResult = searchService.parseQuery(currentUser, jql) if (parseResult.isValid()) { def searchResult = searchService.search(currentUser, parseResult.getQuery(), PagerFilter.getUnlimitedFilter()) for (com.atlassian.jira.issue.DocumentIssueImpl issueDoc : searchResult.getIssues()) { issues.add(issueManager.getIssueObject(issueDoc.getKey())) } }}else { for (String key : keys) { if (issueManager.getIssueByCurrentKey(key) != null) { issues.add(issueManager.getIssueByCurrentKey(key));} }}long start = System.currentTimeMillis();if(checkNumberAffected) { return "The script would run on "+issues.size()+" issues";}for(Issue issue : issues){ MutableIssue mi = (MutableIssue) issue;mi.setCustomFieldValue(targetField, sourceField.getValue(issue)); ComponentAccessor.getIssueManager().updateIssue(currentUser, mi, EventDispatchOption.DO_NOT_DISPATCH, false);boolean wasIndexing = ImportUtils.isIndexIssues() IssueIndexingService issueIndexService = ComponentAccessor.getComponent(IssueIndexingService.class) issueIndexService.reIndex(issue) if(!wasIndexing) ImportUtils.setIndexIssues(true);}end = System.currentTimeMillis();long genTime = end-start;String outString = "Set Values for "+issues.size()+" issues.";outString+=" in "+ genTime +"ms";return outString;
Regards,J
Hi Jeff, Thanks for the script. I tried to fix some errors but the script didn't update the issues.
Because of the error I just changed the for loop
for (com.atlassian.jira.issue.DocumentIssueImpl issueDoc : searchResult.getIssues())
to
for (com.atlassian.jira.issue.Issue issueDoc : searchResult.getIssues()) {issues.add(issueManager.getIssueObject(issueDoc.getKey()))}
Hi Sai,It worked for you after that change?If it did great!Otherwise feel free to ask for assistance.Regards,Jeff
Hi @Jeff Tomband
Is possible to create a job that can daily(automatically scheduled) update the "PC-Status Evaluation" field with the values from "PC-Status"
PC-Status Evaluation - single select list
PC-Status - text field
Thanks!
Yes it is,It's a bit more involved then what you did previously.I'll write up a script for you on my lunch break.Regards,Jeff
@Jeff Tomband much appreciated
Waiting for your code,
Thanks in advance,
Regards
Balaji
I forgot to ask a few details from you.So you have text field containing a word like "Active" or such.You have a single select list where one of the options is "Active".The select list should then select "Active" as it's value.What happens if the text is "asdasdasdasd" and not something that exists in the list.
Hi @Jeff Tomband , I tried your script and it's work really good when I use issues Keys.
Thank's for it !
However, if I use JQL search I have an error :
"org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot cast object 'DocumentIssueImpl[issueKey=ACTI-11]' with class 'com.atlassian.jira.issue.DocumentIssueImpl' to class 'com.atlassian.jira.issue.MutableIssue'"
Any Idea ?
I used really simple JQL as "project = ACTI" or "labels = test"
Best regards,
David
Hi David,What version of Jira is this on?Regards,Jeff
@Jeff Tomband is there a way to map the values from (date due )custom field to (Due Date)system field ?
It looks like you're new here. Sign in or register to get started.