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
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Bridget Sauer
Published yesterday in Marketplace Apps

Calling all developers––You're invited to Atlas Camp 2018

 Atlas Camp   is our developer event which will take place in Barcelona, Spain  from the 6th -7th of   September . This is a great opportunity to meet other developers and get n...

71 views 0 5
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