ScriptRunner Integration
You can access add-on services from Script Runner add-on. Followings are some example scripts. If you need a script, please let us know, it will be easier to write together. Please inspect JavaDoc of add-on's Java API to get an idea of what is possible.
- Displaying Overtime On The Issue
- Displaying Sum of Worklogs by Work Type
- Automatically Logging Work on Issue Transition
Adding a New Single Select Attribute Value Programmatically
import com.deniz.jira.worklog.services.attr.AttrTypeService; import com.deniz.jira.worklog.data.attr.AttrValueImp; import com.onresolve.scriptrunner.runner.customisers.PluginModule; import com.onresolve.scriptrunner.runner.customisers.WithPlugin; @WithPlugin("com.deniz.jira.worklog") @PluginModule AttrTypeService attrTypeService; //Set properties of attribute we want to add AttrValueImp value = new AttrValueImp() value.name = "My New Attribute" value.description="Test Description" //add attribute. Returned AttrValueImp has an "id" field which you can use for further method invocations. AttrValueImp newValue = attrTypeService.addAttrValueToAttrType(2, value)
Following script sets "Invoice Number" worklog attribute for every work logged in the system by listening "Work Logged on Issue" event.
Automatically Setting Worklog Attribute on New Worklogs
import com.deniz.jira.worklog.services.attr.AttrTypeService; import com.deniz.jira.worklog.data.attr.*; import com.onresolve.scriptrunner.runner.customisers.PluginModule; import com.onresolve.scriptrunner.runner.customisers.WithPlugin; import com.atlassian.jira.issue.*; @WithPlugin("com.deniz.jira.worklog") @PluginModule AttrTypeService attrTypeService; def invoiceNumberAttrType = attrTypeService.getAttrTypeWithName("Invoice Number").get(); def worklog = event.getWorklog(); //Every WorklogCreatedEvent has getWorklog() method. Issue issue = worklog.getIssue(); //create a new worklog attribute value AttrWorkLogImp attrWorkLogImp = new AttrWorkLogImp(); //set worklog id, issue id and project id attrWorkLogImp.setWorkLogId(worklog.getId()); attrWorkLogImp.setProjectId(issue.getProjectId()); attrWorkLogImp.setIssueId(issue.getId()); //set type of the attribute and it's value attrWorkLogImp.setAttrTypeId(invoiceNumberAttrType.getID()); attrWorkLogImp.setAttrValue(12345); attrTypeService.addWorkLogAttribute(attrWorkLogImp); //set attribute on worklog
Following script finds text value of submitted single select worklog attribute for every work logged in the system by listening "Work Logged on Issue" event.
How to find text value of submitted worklog attribute
import com.deniz.jira.worklog.services.attr.AttrTypeService; import com.deniz.jira.worklog.data.attr.*; import com.onresolve.scriptrunner.runner.customisers.PluginModule; import com.onresolve.scriptrunner.runner.customisers.WithPlugin; import com.atlassian.jira.issue.*; import org.apache.log4j.Logger import org.apache.log4j.Level def log = Logger.getLogger("com.acme.CreateSubtask") log.setLevel(Level.DEBUG) @WithPlugin("com.deniz.jira.worklog") @PluginModule AttrTypeService attrTypeService; def invoiceNumberAttrType = attrTypeService.getAttrTypeWithName("Invoice Number").get(); //case sensitive def workCodeAttrType = attrTypeService.getAttrTypeWithName("Type of Work").get(); def workCodeAttrTypeImp = attrTypeService.getAttrTypeImpWithId(workCodeAttrType.getID()).get() def worklog = event.getWorklog(); log.debug("Script starting"); Thread.start{ System.sleep(100); def existingAttributesList = attrTypeService.getWorkLogAttrList(worklog.getId()) log.debug("existingAttributesList = ${existingAttributesList}") existingAttributesList.each { attr -> log.debug("attr.id:" + attr.id); log.debug("attr.type:" + attr.attrTypeId); log.debug("attr.value:" + attr.attrValue); log.debug("attr.valueFormatted:" + attr.attrValueFormatted); } def existingWorkCodeAttr = existingAttributesList.find {attr -> attr.attrTypeId == workCodeAttrType.getID()} log.debug("Value of Existing Work Code as Int:" + existingWorkCodeAttr.attrValue); def existingWorkCodeAttrDefinition = workCodeAttrTypeImp.attributeValues.find{ attrValue -> attrValue.id == Integer.valueOf(existingWorkCodeAttr.attrValue.toString())} log.debug("Value of Existing Work Code as Text:" + existingWorkCodeAttrDefinition.name) }