Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

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.

Code Block
languagegroovy
firstlinetitleHow 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)    
}

...