Degraded performance Customers may experience intermittent errors using Community search. Our platform vendor is investigating.
It's not the same without you
Join the community to find out what other Atlassian users are discussing, debating and creating.
Hi Everyone,
I am wondering if there is a way to pull two custom date fields and then subtract them to find the time difference inbetween these two date fields. I am try to use this to be able to log this time automatically inside of Tempo. I imported a lot of plugins just to make sure that I am not missing out on any functions. My code so far can be seen at the bellow:
import java.util.*
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 com.atlassian.jira.issue.CustomFieldManager;
import com.atlassian.jira.issue.fields.CustomField;
import com.atlassian.jira.ComponentManager;
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.IssueManager;
import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.issue.MutableIssue;
import com.atlassian.jira.issue.customfields.manager.OptionsManager
import static java.lang.Math.*
import java.sql.Timestamp
import com.onresolve.jira.groovy.jql.JqlQueryFunction
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 is.origo.jira.plugin.common.TempoWorklogManager
import com.tempoplugin.core.datetime.api.TempoDateTime
def componentManager = ComponentManager.instance
def optionsManager = ComponentManager.getComponentInstanceOfType(OptionsManager.class)
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def cfend = customFieldManager.getCustomFieldObjectByName("End Date")
def cfstart = customFieldManager.getCustomFieldObjectByName("Start Date")
def reporter = issue.reporter.name
def stDate = issue.getCustomFieldValue(cfend)
def enDate = issue.getCustomFieldValue(cfstart)
def timediff = enDate-stDate
@WithPlugin("is.origo.jira.tempo-plugin")
@PluginModule
TempoWorklogManager tempoWorklogManager
@PluginModule
WorkAttributeService workAttributeService
def changeHistoryManager = ComponentAccessor.getChangeHistoryManager()
def triageType = workAttributeService.getWorkAttributeTypes().returnedValue.find{it.name == "_WorkType_"}
def attributes = workAttributeService.getWorkAttributesByType(triageType).returnedValue // set the Tempo Worktype attribute
tempoWorklogManager.create(issue.key, TempoDateTime.now(), "Auto-created worklog for Vacation",
attributes,
timediff, 0, null,
issue.reporter, [:])
I know there was a way to log work without tempo (WorklogImp or WorklogImp2) but I had trouble using those functions so I am trying to use the tempoWorklogManager now. I also get issues with the tempoWorklogManager.create command.
Update: I changed the below lines
def stDate = issue.getCustomFieldValue(cfend)
def enDate = issue.getCustomFieldValue(cfstart)
def timediff = enDate-stDate
To :
double stDate = (issue.getCustomFieldValue(cfend) as Date).getTime()//returns milliseconds
double enDate = (issue.getCustomFieldValue(cfstart) as Date).getTime()//returns milliseconds
double timediff = (enDate - stDate)*1000 // returns seconds
timediff = timediff/(60*60) // returns hours
This hopefully is able to take my dates, conert them to double and find the time difference inbetween them.
I am still trying to find a way to log the time difference in either the tempo timesheets or JIRA
This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.
Read moreHey Atlassian Community! Today we are launching a bunch of customer stories about the amazing work teams, like Dropbox and Twilio, are doing with Jira. You can check out the stories here. The thi...
Connect with like-minded Atlassian users at free events near you!
Find a groupConnect with like-minded Atlassian users at free events near you!
Unfortunately there are no AUG chapters near you at the moment.
Start an AUGYou're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.