Hi all,
I created new issue type called "Sprint":
-With summary that looks like in regular issue sprint custom fieldץ
-With start and end time.
I would like to create a script listener with trigger "Issue Updated" that will copy the start and end time from "Sprint" issue (with the same summary of script custom field of the issue) and insert it to start and end time of the specific issue.
I didn't success to use 2 different issue type in the script listener, so for now I refer to specific issues.
Can anyone can help me understand why the start and end time of the relevant issue didn't changed?
My Code for now:
IssueManager issueManager = ComponentAccessor.getOSGiComponentInstanceOfType(IssueManager.class);
Issue issue = issueManager.getIssueObject("WBL-46003");
CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager();
//If Custom Field of issue is not null
if (customFieldManager.getCustomFieldObjectByName("Sprint")!=null)
{
List<String> curSpr = (List<String>) issue.getCustomFieldValue(customFieldManager.getCustomFieldObjectByName("Sprint"));
def name= curSpr[0].getName();
CustomField issueStartDate = customFieldManager.getCustomFieldObjectByName("Sprint Start Date");
CustomField issueEndDate = customFieldManager.getCustomFieldObjectByName("Sprint End Date");
Issue spr = issueManager.getIssueObject("WBL-46075");
//Take Sprint issue- start & end date
def issuetype = spr.getIssueType().name;
if(issuetype=="Sprint")
{
def summary = spr.getSummary().toString();
if(summary==name)
{
//sprint
def startDate = customFieldManager.getCustomFieldObjects(spr).find {it.name == "Sprint Start Date"};
def endDate = customFieldManager.getCustomFieldObjects(spr).find {it.name == "Sprint End Date"};
Object startDateVal = startDate.getValue(spr);
Object endDateVal = endDate.getValue(spr);
IssueChangeHolder changeHolder = new DefaultIssueChangeHolder();
issueStartDate.updateValue(null, spr, new ModifiedValue(issue.getCustomFieldValue(issueStartDate), startDate), changeHolder);
issueEndDate.updateValue(null, spr, new ModifiedValue(issue.getCustomFieldValue(issueEndDate), endDate), changeHolder);
return issueStartDate;
return issueEndDate;
}
}
Hello,
What are the error in atlassian-jira.log file. Also you should log some info about your script execution into the atlassia-jira.log file.
you can use log.error("summary: " + summary) to log the value of the summary variable.
I do not understand your code. You take two fields and then you update them with the values that are in this fields. Why would you do it? Usually a script takes a value from a field and updates another field.
Also the second return statement is never reached in your script. You can delete it. More over why would you return a value at all?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I would like to take the values from fields start\end sprint date in "Sprint" issue and paste them in fields start\end sprint date in all other issues (story, bug..).
The trigger should be while the other issue updated.
I tried to do it with: compare the "sprint field name" (of the updated issue) with the summary of the "Sprint" issue -> then take the values from the start\end sprint field and do the copy.
I started work with Groovy and Jira one month ago so it's very new for me..
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I got it. It should be like this
issueStartDate.updateValue(null, spr, new ModifiedValue("", issue.getCustomFieldValue(issueStartDate)), changeHolder);
issueEndDate.updateValue(null, spr, new ModifiedValue("", issue.getCustomFieldValue(issueEndDate)), changeHolder);
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
those lines above set the issueStartDate field of the spr issue from the values of the current issue. Is it what you want?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
If you want from spr value to the current issue then change it like this
issueStartDate.updateValue(null, issue, new ModifiedValue("", spr.getCustomFieldValue(issueStartDate)), changeHolder);
issueEndDate.updateValue(null, issue, new ModifiedValue("", spr.getCustomFieldValue(issueEndDate)), changeHolder);
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thank you!!!!!!!!! Work!
Now, Do you have an idea how can I change it to something generic ? not a specific "Sprint" issue (spr)... Maybe a list with issuetype=Sprint ?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You can use a jql query to get a list of issues where issuetype = Sprint.
You can find an example here:
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
A listener work just for an event for a single issue. If you want to choose other issues, you can get a list of issues by a JQL condition. The code would look like this:
def findIssues(String jqlQuery) {
def issueManager = ComponentAccessor.issueManager
def user = ComponentAccessor.jiraAuthenticationContext.user
def jqlQueryParser = ComponentAccessor.getComponent(JqlQueryParser.class)
def searchProvider = ComponentAccessor.getComponent(SearchProvider.class)
def query = jqlQueryParser.parseQuery(jqlQuery)
def results = searchProvider.search(query, user, PagerFilter.unlimitedFilter)
results.issues.collect
{ issue -> issueManager.getIssueObject(issue.id) }
}
def jqlQuery = "issuetype = Sprint"
def issues = findIssues(jqlQuery)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Since you are using script runner, my suggestion to you is to try out the code in the "Script console" with proper logging so that you can see the log output on the console itself.
https://www.adaptavist.com/doco/display/SFJ/Set+logging+to+help+debug+your+scripts
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi
I try it with script console ..
return issueStartDate;
return issueEndDate;
}
The results was good and gave me the start and end dates of the 'Sprint' issue.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Here's the problem in your code
issueStartDate.updateValue(null, spr, new ModifiedValue(issue.getCustomFieldValue(issueStartDate), startDate), changeHolder);
You are passing custom field object "startDate" in the ModifiedValue constructor, it expects an value and not an object. Thus, you should pass "startDateVal " instead of "startDate" and that should do the trick!
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.