A class is created as custom listner and uploaded in jira server. The script in class works fine in console but does not work as custom listner.
Please help.
What's the exception you get? Did you diclare a package for the class? Did you try runnign a simple hello world line as a class from a script listener?
Really appreciate quick reply on this. I did not get any exception. Actually, my aim is to update a custom field on basis of other 4 custom fields. I wrote a script which worked fine in console and updated the issue. I put the script in a class and saved class in /WEB-INF/classes/com/util folder.
Following is code for the same
import com.atlassian.jira.ComponentManagerimport com.atlassian.jira.issue.CustomFieldManagerimport com.atlassian.jira.issue.fields.CustomFieldimport com.atlassian.jira.issue.IssueManagerimport com.atlassian.jira.issue.Issuecom.atlassian.jira.issue.MutableIssueimport com.atlassian.jira.issue.ModifiedValueimport com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.opensymphony.workflow.WorkflowContextimport com.atlassian.jira.event.issue.AbstractIssueEventListenerimport com.atlassian.jira.event.issue.IssueEventimport org.apache.log4j.Loggerimport static org.apache.log4j.Level.DEBUGimport com.atlassian.jira.bc.issue.IssueService.UpdateValidationResultimport com.atlassian.jira.bc.issue.IssueService.IssueResultimport com.atlassian.jira.bc.issue.IssueServiceimport com.atlassian.jira.bc.issue.IssueService.TransitionValidationResultimport com.atlassian.jira.issue.IssueInputParametersImplimport com.atlassian.jira.issue.IssueInputParametersimport com.atlassian.jira.util.ErrorCollectionimport com.atlassian.jira.issue.index.IssueIndexManagerimport java.sql.Timestampimport com.atlassian.jira.issue.comments.CommentManagerimport com.atlassian.crowd.embedded.api.Userimport com.atlassian.jira.component.ComponentAccessorimport com.atlassian.jira.user.ApplicationUserimport com.atlassian.jira.issue.MutableIssueimport com.atlassian.jira.event.type.EventDispatchOption
class UpdateField extends AbstractIssueEventListener {
Logger log = Logger.getLogger(UpdateField.class)
@Override void workflowEvent(IssueEvent event) { log.setLevel(org.apache.log4j.Level.DEBUG)
IssueManager issueManager = ComponentManager.getInstance().getIssueManager()
CustomFieldManager customFieldManager = ComponentManager.getInstance().getCustomFieldManager()
MutableIssue issue = event.issue if (issue.project.name == 'Program Backlog KANBAN') {
def changeHolder = new DefaultIssueChangeHolder()
CustomField customField_1 = customFieldManager.getCustomFieldObjectByName( "SAFe Job Size" )
CustomField customField_2 = customFieldManager.getCustomFieldObjectByName( "SAFe RiskReduction OpportunityEnablement" )
CustomField customField_3 = customFieldManager.getCustomFieldObjectByName( "SAFe Time Criticality" )
CustomField customField_4 = customFieldManager.getCustomFieldObjectByName( "SAFe User-Business Value")
CustomField customField_5 = customFieldManager.getCustomFieldObjectByName( "SAFe WSJF")
try {
def test = ((issue.getCustomFieldValue(customField_2) == null ? 0 : issue.getCustomFieldValue(customField_2)) + (issue.getCustomFieldValue(customField_3) == null ? 0 : issue.getCustomFieldValue(customField_3)) + (issue.getCustomFieldValue(customField_4) == null ? 0 : issue.getCustomFieldValue(customField_4)) )/issue.getCustomFieldValue(customField_1) customField_5.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(customField_5), test),changeHolder)
}
catch (Exception ex) { customField_5.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(customField_5), null),changeHolder)
}
finally {
} } }}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
You don't need the beginning, just start your script from log.setLevel(org.apache.log4j.Level.DEBUG) and also leave the import statements.
Also, try with inline first. Make sure your code works and then place the script under \Application Data\JIRA\scripts
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
ok, then can I call this script file from issue updated/created events in a project as a custom event listner? Sorry, I am new to Jira scripting. Really appreciate your response. And how do I debug on Jira server?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Shruti Jain,
Sorry for the late response.
Yes, you simply define a custom scripted listener, set triggers (issue created/updated) and paste your script inside.
In order to debug just use log.debug() statements. You should find the print outs in the atlassian-jira.log file on the server. There's also a scirpt runner built-in script you can use in order to read the server log files in case you don't have the login to the server.
Tanya
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
No worries. Really appreciate your response. I will try this. Hey, I have another question. Does it also work on Jira cloud?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Yes, it should work the same if you have script runner for Jira cloud installed
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Tanya - What will I replace the following line with to get current event when this script is attached to issue updated/created event?
MutableIssue issue = event.issue
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.