Hi
i need to change this current script listener in to a service to execute once a day.
I understand how to set the service up etc but i realised my code doesn't actually get all issues from all projects, it only gets the issue that triggered the listener.
I need to change my code to get all projects and all issues within the projects to check if they have an estimate, i hope you can help as i will need to integrate this in to a lot more of my other reporting scripts. Thanks in advanced!
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
def Category log = Category.getInstance("com.onresolve.jira.groovy")
log.setLevel(org.apache.log4j.Level.DEBUG)
log.debug("start of code")
def estField = ComponentAccessor.getCustomFieldManager().getCustomFieldObject(11401)
def cFieldValue = issue.getCustomFieldValue(estField)
log.debug(cFieldValue)
Issue issue = event.issue
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 = "test@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")
}
}
Yes that's possible.
You can either use the form-base configuration in behavior and select those fields.
Or if you want to access them via scripts, you'll use the getFieldById() method.
There are different ways to identify the field id. I personally like to just examine the page html using the browser developer tools. Open the form with the field you want to hide, right-click on the field and select inspect.
For example, doing that on the fix version, you will see something like this:
I have highlighted where I found the field ID.
You can also use the form-base configuration, add the field and save, then examine the behaviour rest output:
<baseUrl>/rest/scriptrunner/behaviours/latest/config/<id>It will show you the fields you selected and their ids
Hey Peter,
That worked like a charm, you saved my day. :)
Thanks a lot !!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hey @PD Sheehan ,It worked (Inspect thing) for all other fields correctly & guess where it didn't work, fixVersions field is not getting hidden with it, I tried to hide with both methods getFieldByID() & getFieldByName() but no success, anything that you could think off ?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Any errors in your atlassian-jira.log file when you open your create form and expect the field to be hidden?
It should definitely work with getFieldById('fixVersions')
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
hey @PD Sheehan There is no error as such, but somehow its not working. I just noticed that upon clinking inspect, Fix Version field is not showing field ID like yours, for other fields it does show to me as well.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Probably a difference in jira version or version field display configuration difference.
Try this:
In behaviours, add the fixVersion Field and save your behaviour.
Look at the URL
Now, change the plugins/sevlet/scriptrunner/admin/behaviours/edit part of the URL with wih rest/scriptrunner/behaviour/latest/config
This will show you exactly what your field ID is.
If your script still doesn't work with that id, you'll have to share your full script for debugging.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
a
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.