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

This widget could not be displayed.

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]

)

 

This widget could not be displayed.

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

This widget could not be displayed.

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
Community showcase
Published Aug 22, 2018 in Marketplace Apps

How a Marketplace app tech team is achieving gender diversity

Hello! My name is Genevieve Blanch, and I'm the Marketing Manager at RefinedWiki, creators of apps to give teams the tools to customize Atlassian platforms. Currently, 44% of the tech team at Re...

523 views 3 19
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