Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,367,320
Community Members
 
Community Events
168
Community Groups

Trying to migrate a scripted field (scriptrunner) from server to cloud, for time difference

Hello everyone!

I'm trying to reuse a server script on cloud, but i'm not too good at scriptrunner. 

On server, this is the script for the field:


import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.history.ChangeItemBean

def changeHistoryManager = ComponentAccessor.getChangeHistoryManager()

def deployName = "DEV Deploy Delay"

List<Long> rt = [0L]
def changeItems = changeHistoryManager.getChangeItemsForField(issue, "status")
changeItems.reverse().each { ChangeItemBean item ->
def timeDiff = System.currentTimeMillis() - item.created.getTime()
if (item.fromString == deployName) {
rt << -timeDiff
}
if (item.toString == deployName) {
rt << timeDiff
}
}

def total = rt.sum() as Long
return (total / 1000) as long ?: 0L

 For cloud, I tried re-using snippets from a different script I found online for calculating the time an issue has been in a status, so I've adapted the above script with the new imports and changed some things as well, but I'm getting an error at the "ChangeItemBean item" line and I'm stuck without knowing what to replace that line with.

This is what I was going for on cloud:

import java.time.ZonedDateTime
import java.time.format.DateTimeFormatter
import java.text.SimpleDateFormat;
import java.util.Date;

def changeHistoryManager = get("/rest/api/3/issue/${issue.key}/changelog").asObject(Map).body.values.findAll{it.items.field.contains("status")}
def totalStatusTime = [0L]

def deployName = "DEV Deploy Delay"

List<Long> rt = [0L]
def changeItems = changeHistoryManager.getChangeItemsForField(issue, "status")
changeItems.reverse().each { ChangeItemBean item ->
def timeDiff = System.currentTimeMillis() - item.created.getTime()
if (item.fromString == deployName) {
rt << -timeDiff
}
if (item.toString == deployName) {
rt << timeDiff
}
}

def total = rt.sum() as Long
return (total / 1000) as long ?: 0L

But i'm getting an error 'Unable to resolve class  ChangeItemBean' @ line 13.
Again, I'm very new to scriptrunner, and quite the noob in programming, so I got stuck here and couldn't find any aid on the documentations as to how to proceed.

Does anyone have an idea?

Thank you!!!

1 answer

0 votes

Welcome to the Atlassian Community!

Cloud and Server/DC are very different systems, and so are the Scriptrunner apps for them.  I think it was the Team event in Barcelona just after we released SR for Cloud where Jon Mort opened the talk on how his team wrote it with "we started again, writing it from scratch".

Server/DC scripts won't work on Cloud (and vice-versa).

The standard doc is https://docs.adaptavist.com/sr4js/latest/scriptrunner-migration/migrating-to-or-from-cloud/migrate-from-scriptrunner-for-jira-server-to-cloud and although it's got a pile of hints and tips, it does boil down to "you need to rewrite it"

Hey Nic! Thanks for the reply!

Yes, that's the thing... I am rewritting it, replacing bits with similar cloud scripts I find online, but the 'changeitembean' part is the only one I can't find an equivalent for.

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
FREE
TAGS

Atlassian Community Events