Hi All
I have Script runner installed version 4.1.2 on production JIRA version 6.4.12.
I have two script which is giving error while doing JIRA re-indexing for some issues not all the issue we having in jira.
For getting members:
import com.atlassian.jira.component.ComponentAccessor
def groupManager = ComponentAccessor.getGroupManager()
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def cf = customFieldManager.getCustomFieldObjectByName("Group to maintain")
def theusers = groupManager.getUsersInGroup(issue.getCustomFieldValue(cf))
def thetext = ""
theusers.each() {
thetext += it.getDisplayName() + " (" + it.getName() + ")<br>"
}
return thetext
For getting age
import com.atlassian.jira.component.ComponentAccessor
def groupManager = ComponentAccessor.getGroupManager()
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def cf = customFieldManager.getCustomFieldObjectByName("Date Opportunity Identified")
def dateOppIdef = issue.getCustomFieldValue(cf)
def ageInDays="";
if(dateOppIdef!=""){
ageInDays=new Date() - dateOppIdef;
}
return ageInDays.toString();
The error is as such
2016-12-04 09:32:38,914 IssueIndexer:thread-19 ERROR asin17 563x205x1 1ily4nh 14.140.116.135 /secure/admin/IndexReIndex.jspa [onresolve.scriptrunner.customfield.GroovyCustomField] Script field failed on issue: SSGM-2582, field: Members org.codehaus.groovy.runtime.metaclass.MethodSelectionException: Could not find which method getUsersInGroup() to invoke from this list: public abstract java.util.Collection com.atlassian.jira.security.groups.GroupManager#getUsersInGroup(com.atlassian.crowd.embedded.api.Group) public abstract java.util.Collection com.atlassian.jira.security.groups.GroupManager#getUsersInGroup(java.lang.String) at Script1.run(Script1.groovy:5)
2016-12-04 09:23:48,058 IssueIndexer:thread-42 ERROR asin17 563x205x1 1ily4nh 14.140.116.135 /secure/admin/IndexReIndex.jspa [onresolve.scriptrunner.customfield.GroovyCustomField] Script field failed on issue: PSGD-410, field: Age (in days) java.lang.NullPointerException at Script3.run(Script3.groovy:8)
Also when i am using Script console and try to fix the issue,I am getting below error:
No signature of method: com.atlassian.jira.issue.managers.DefaultIssueManager.getCustomFieldValue() is applicable for argument types: (com.atlassian.jira.issue.fields.CustomFieldImpl) values: [Group to maintain]
This code is strange. Here is a refactored vervions:
import com.atlassian.jira.component.ComponentAccessor StringBuilder thetext = new StringBuilder() ComponentAccessor.getGroupManager().getUsersInGroup( ((ArrayList<Object>) issue.getCustomFieldValue(ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Group to maintain"))).get(0)) .each() { thetext.append(it.getDisplayName()).append(" (").append(it.getName()).append(")<br>"); } return thetext.toString()
import com.atlassian.jira.component.ComponentAccessor import java.sql.Timestamp Timestamp dateOppIdef = issue.getCustomFieldValue(ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Date Opportunity Identified")) int ageInDays = 0; if(dateOppIdef != null){ ageInDays = (System.currentTimeMillis() - dateOppIdef.getTime())/(60*60*24*1000) } return String.valueOf(ageInDays);
Hi Vasiliy
Still above code is not working on Script console.I am getting below error
Error
No such property: issue for class: Script6
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
When you run script for script condition, validator or postfunction you have predefined variable issue which corresponds to current issue.
If you want to run script via script console you have to define and initialise this variable manually. I usually use this (replace "issueKey" with actial issue key):
Issue issue = ComponentAccessor.getIssueManager().getIssueObject("issueKey")
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
import com.atlassian.jira.component.ComponentAccessor
Issue issue = ComponentAccessor.getIssueManager().getIssueObject("GME-17730")
StringBuilder thetext = new StringBuilder()
ComponentAccessor.getGroupManager().getUsersInGroup(
((ArrayList<Object>) issue.getCustomFieldValue(ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Group to maintain"))).get(0))
.each() {
thetext.append(it.getDisplayName()).append(" (").append(it.getName()).append(")<br>");
}
return thetext.toString()
I run above code in script console but still getting error.Please check below
Error
startup failed: Script15.groovy: 3: unable to resolve class Issue @ line 3, column 7. Issue issue = ComponentAccessor.getIssueManager().getIssueObject("GME-17730") ^ 1 error
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Try this one:
import com.atlassian.jira.component.ComponentAccessor import com.atlassian.jira.issue.Issue Issue issue = ComponentAccessor.getIssueManager().getIssueObject("GME-17730") StringBuilder thetext = new StringBuilder() ComponentAccessor.getGroupManager().getUsersInGroup( ((ArrayList<Object>) issue.getCustomFieldValue(ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Group to maintain"))).get(0)) .each() { thetext.append(it.getDisplayName()).append(" (").append(it.getName()).append(")<br>"); } return thetext.toString()
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
No success!! Getting below error message.
Error
Cannot invoke method get() on null object
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
It means that value of custom field for this issue is empty. Here is hew version
import com.atlassian.jira.component.ComponentAccessor import com.atlassian.jira.issue.Issue Issue issue = ComponentAccessor.getIssueManager().getIssueObject("GME-17730") StringBuilder thetext = new StringBuilder() try{ ComponentAccessor.getGroupManager().getUsersInGroup( ((ArrayList<Object>) issue.getCustomFieldValue(ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Group to maintain"))).get(0)) .each() { thetext.append(it.getDisplayName()).append(" (").append(it.getName()).append(")<br>"); } } catch (NullPointerException e){ return "" } return thetext.toString()
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks Vasiliy for your support now i will apply your suggested script on JIRA and will update you.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.