Doc for Script Runner SDK

Иван Михеев July 30, 2017

JIRA Server 7.3.7 and SR 5.0.14
I have follow code which save the status for work log in Tempo Work Attributes

import com.atlassian.jira.component.ComponentAccessor
import com.onresolve.scriptrunner.runner.ScriptRunnerImpl
import com.onresolve.scriptrunner.runner.customisers.PluginModule
import com.onresolve.scriptrunner.runner.customisers.WithPlugin
import com.tempoplugin.core.workattribute.api.WorkAttributeService
import is.origo.jira.plugin.common.TempoWorklogManager
import com.tempoplugin.core.datetime.api.TempoDateTime
import org.apache.log4j.Category

@WithPlugin("is.origo.jira.tempo-plugin")

@PluginModule
TempoWorklogManager tempoWorklogManager

@PluginModule
WorkAttributeService workAttributeService

def worklog = event.getWorklog()
def issue = event.getIssue()
//def currentUser = ComponentAccessor.getJiraAuthenticationContext().getUser()
def changeHistoryManager = ComponentAccessor.getChangeHistoryManager()

def changeHistoryItems = changeHistoryManager.getAllChangeItems(issue).reverse()

def LastStatus = changeHistoryItems.find {
it.field == "status"
}

def lastStatusName = LastStatus.toValues.values()
def Category log = Category.getInstance("com.onresolve.jira.groovy.InstallListener")
log.setLevel(org.apache.log4j.Level.DEBUG)
def triageType = workAttributeService.getWorkAttributeTypes().returnedValue.find{it.name == "_WorkType_"}

tempoWorklogManager.updateWorklogAttributes(
worklog.getId().toString(),
["_Status_": lastStatusName]
)

But there is undefined method: 

tempoWorklogManager.updateWorklogAttributes(
worklog.getId().toString(),
["_Status_": lastStatusName]
)

Could you help me to find documentation about using methods of components, or tell me where is the error

import com.tempoplugin.core.workattribute.api.WorkAttributeService
import is.origo.jira.plugin.common.TempoWorklogManager

 

Thank you

 

 

 

 

 

3 answers

0 votes
Иван Михеев August 1, 2017

Find a solution for creating 

def workAttrBuilder = new WorkAttributeValue.Builder(
worklog.getId(),
attribute
).value(lastStatusName.toString())

def workAttr = workAttrBuilder.build();
workAttributeValueService.createWorkAttributeValuesByWorklog(worklog.getId() , [workAttr])

 

But can't get it work with updating

def workAttrUpdBuilder = new WorkAttributeValue.Builder(atributeValue).value(lastStatusName.toString())

WorkAttributeValue workUpdAttr = workAttrUpdBuilder.build()
def res = workAttributeValueService.updateWorkAttributeValue(workUpdAttr)

Could you help me with it?  

0 votes
Иван Михеев July 31, 2017

My point is that the method 

tempoWorklogManager.updateWorklogAttributes(

worklog.getId().toString(),

["_Status_": lastStatusName]

)

Doesn't exist in the class TempoWorklogManager

So my task is to update or create tempo worklog attributes

I find the WorklogAtributeValueService class but i can't figure out how it works

0 votes
Joshua Yamdogo @ Adaptavist
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 31, 2017

I can see that this script produces a static type checking error in the inline editor, but have you actually tried running it? What errors do you get? Sometimes the inline editor will tell you the method can't be found, but the script will still work. Also, have you tried explicitly defining the IssueEvent?

import com.atlassian.jira.component.ComponentAccessor

import com.onresolve.scriptrunner.runner.ScriptRunnerImpl

import com.onresolve.scriptrunner.runner.customisers.PluginModule

import com.onresolve.scriptrunner.runner.customisers.WithPlugin

import com.tempoplugin.core.workattribute.api.WorkAttributeService

import is.origo.jira.plugin.common.TempoWorklogManager

import com.tempoplugin.core.datetime.api.TempoDateTime

import org.apache.log4j.Category

import com.atlassian.jira.event.issue.IssueEvent

 

@WithPlugin("is.origo.jira.tempo-plugin")

 

@PluginModule

TempoWorklogManager tempoWorklogManager

 

@PluginModule

WorkAttributeService workAttributeService

 

def event = event as IssueEvent

def worklog = event.getWorklog()

def issue = event.getIssue()

//def currentUser = ComponentAccessor.getJiraAuthenticationContext().getUser()

def changeHistoryManager = ComponentAccessor.getChangeHistoryManager()

 

def changeHistoryItems = changeHistoryManager.getAllChangeItems(issue).reverse()

 

def LastStatus = changeHistoryItems.find {

it.field == "status"

}

 

def lastStatusName = LastStatus.toValues.values()

def Category log = Category.getInstance("com.onresolve.jira.groovy.InstallListener")

log.setLevel(org.apache.log4j.Level.DEBUG)

def triageType = workAttributeService.getWorkAttributeTypes().returnedValue.find{it.name == "_WorkType_"}

 

tempoWorklogManager.updateWorklogAttributes(

worklog.getId().toString(),

["_Status_": lastStatusName]

)

 

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events