Hi
So i am trying to get the value of a custom field that stores the remaining time, here is my code
def estField = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Total Remaining Estimate")
def cFieldValue = (double) issues.getCustomFieldValue(estField)
In my logs this is returning the following error
2018-06-07 17:45:02,439 Caesium-1-1 ERROR anonymous no estimate - send email [c.o.jira.groovy.GroovyService] Script service failed: D:\Atlassian\scripts\IHNE.groovy
groovy.lang.MissingMethodException: No signature of method: java.util.ArrayList.getCustomFieldValue() is applicable for argument types: (com.atlassian.jira.issue.fields.ImmutableCustomField) values: [Total Remaining Estimate]
Hope someone is able to answer/resolve this issue for me as i am stumped.
Kindest regards and many thanks
Tyler
Hello,
How do you initialize the issues variable? It is an ArrayList. I guess it is an ArrayList<Issue>. But to make sure I need to see your code.
If it is ArrayList<Issue> it would work like this:
def estField = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Total Remaining Estimate")
def cFieldValue
issues.each{
cFieldValue = (double) it.getCustomFieldValue(estField)
}
Thanks for the reply, this is my full code:
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.CustomFieldManager
import java.util.logging.Logger
import com.atlassian.mail.Email
import com.atlassian.mail.server.MailServerManager
import com.atlassian.mail.server.SMTPMailServer
import com.atlassian.jira.component.ComponentAccessor
import org.apache.log4j.Category
import com.atlassian.jira.bc.issue.search.SearchService
import com.atlassian.jira.user.util.UserUtil
import com.atlassian.jira.user.util.UserManager
import com.atlassian.crowd.embedded.api.User
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.web.bean.PagerFilter
def Category log = Category.getInstance("com.onresolve.jira.groovy")
log.setLevel(org.apache.log4j.Level.DEBUG)
log.debug("start of code")
jqlSearch = 'updated >= -4w'; // Create the JQL query to perform
SearchService searchService = ComponentAccessor.getComponent(SearchService.class);
UserUtil userUtil = ComponentAccessor.getUserUtil();
def user = ComponentAccessor.getUserManager().getUserByName("jira_bot")
// Set the default list of issues to null just to be safe
List<Issue> issues = null;
// Perform the search as a user and return the result so it can be validated.
SearchService.ParseResult parseResult = searchService.parseQuery(user, jqlSearch);
if(parseResult.isValid()){
log.debug("inside parse if")
def searchResult = searchService.search(user, parseResult.getQuery(), PagerFilter.getUnlimitedFilter());
issues = searchResult.issues
log.debug(issues)
issues.each(){
log.debug("inside loop")
def estField = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Total Remaining Estimate")
def cFieldValue = (double) issues.getCustomFieldValue(estField)
log.debug(cFieldValue)
if ( cFieldValue == 0.0) {
def subject = "${issues.key} has no Estimate"
def body = "https://test.atlassian.net/issue/${issues.key} \n This issue does not have an estimate"
def emailAddr = "bot@test.com"
SMTPMailServer mailServer = ComponentAccessor.getMailServerManager().getDefaultSMTPMailServer()
if (mailServer) {
Email email = new Email(emailAddr);
email.setSubject(subject);
email.setBody(body.toString());
mailServer.send(email);
log.debug("Mail sent")
}
else {
log.debug("Please make sure that a valid mailServer is configured")
}
}
}
}
else{
log.error("Invalid JQL: " + jqlSearch);
}
Hope you are able to identify the issue a bit better now, Thanks @Alexey Matveev
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thank you for the code. It should be like this:
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.CustomFieldManager
import java.util.logging.Logger
import com.atlassian.mail.Email
import com.atlassian.mail.server.MailServerManager
import com.atlassian.mail.server.SMTPMailServer
import com.atlassian.jira.component.ComponentAccessor
import org.apache.log4j.Category
import com.atlassian.jira.bc.issue.search.SearchService
import com.atlassian.jira.user.util.UserUtil
import com.atlassian.jira.user.util.UserManager
import com.atlassian.crowd.embedded.api.User
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.web.bean.PagerFilter
def Category log = Category.getInstance("com.onresolve.jira.groovy")
log.setLevel(org.apache.log4j.Level.DEBUG)
log.debug("start of code")
jqlSearch = 'updated >= -4w'; // Create the JQL query to perform
SearchService searchService = ComponentAccessor.getComponent(SearchService.class);
UserUtil userUtil = ComponentAccessor.getUserUtil();
def user = ComponentAccessor.getUserManager().getUserByName("jira_bot")
// Set the default list of issues to null just to be safe
List<Issue> issues = null;
// Perform the search as a user and return the result so it can be validated.
SearchService.ParseResult parseResult = searchService.parseQuery(user, jqlSearch);
if(parseResult.isValid()){
log.debug("inside parse if")
def searchResult = searchService.search(user, parseResult.getQuery(), PagerFilter.getUnlimitedFilter());
issues = searchResult.issues
log.debug(issues)
issues.each(){ issue ->
log.debug("inside loop")
def estField = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Total Remaining Estimate")
def cFieldValue = (double) issue.getCustomFieldValue(estField)
log.debug(cFieldValue)
if ( cFieldValue == 0.0) {
def subject = "${issue.key} has no Estimate"
def body = "https://test.atlassian.net/issue/${issue.key} \n This issue does not have an estimate"
def emailAddr = "bot@test.com"
SMTPMailServer mailServer = ComponentAccessor.getMailServerManager().getDefaultSMTPMailServer()
if (mailServer) {
Email email = new Email(emailAddr);
email.setSubject(subject);
email.setBody(body.toString());
mailServer.send(email);
log.debug("Mail sent")
}
else {
log.debug("Please make sure that a valid mailServer is configured")
}
}
}
}
else{
log.error("Invalid JQL: " + jqlSearch);
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You're great, thanks for this it has got it working.
Could you explain what issue -> does within the loop please? just so i know for future reference.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
When you do a loop with the each statement you can reference each element of an array with the it variable. But I tend to rename this variable so, that it would be more understandable. That is why issue -> means that you will be using the issue variable instead of the it variable. If you remove the issue -> part, then you can change all issue. parts with the it. part.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Ahh, thanks for the great explanation. I will use this more in the future, thank you again @Alexey Matveev you have been a valid source of help and information these past days.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Tyler Brown-Jones you are welcome!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Try to use like this and check
import com.atlassian.jira.issue.fields.CustomField;
CustomField cf = ComponentAccessor.getCustomFieldManager().getCustomFieldObject(new Long(10266));
Issues.getCustomFieldValue(cf)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
that's exactly what i did apart i referenced by name as it works fine for immutableCustomFields , but why the (new Long(10266)) part in your code?
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.