Doc for Script Runner SDK

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

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]

)

 

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

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?  

Suggest an answer

Log in or Sign up to answer
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Published Jul 10, 2018 in Marketplace Apps

If you’re an Atlassian app developer, you’ll want to know about Atlas Camp!

This September 6-7, hundreds of Atlassian App developers will flock to Barcelona Spain to build skills, discover product roadmaps, meet face-to-face with the Atlassian team, and learn how to extend t...

179 views 0 4
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you