Hi,
Globally we are using JIRA and need to record when something is marked as done it stores the local date on the users machine not the date on the server for that issue.
How can i achieve this? i know it will need to be coded but im not sure on how to achieve this, i do have script runner.
"when something is marked as done it stores the local date on the users machine not the date on the server for that issue"
That's not the case... it stores the server date but will display the date in the timezone of whoever is looking at it. At least that's since JIRA 4.4.
If you want to get the user timezone, you will need to look up the timezone preference for the user and make the adjustment.
Thats the problem........ for reporting purposes i dont want to change my timezone to each different destination every time i have to do reports.. we have over 8 timezones across various projects... i need to calculate from this date to this date regardless of timezone thus having a field that stores the local machine time a way to solve this problem
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
So, you need to perform two steps:
1) learn how to update custom field of date type
2) learn how to get local type.
Lets start with step 1:
import com.atlassian.jira.component.ComponentAccessor import com.atlassian.jira.event.type.EventDispatchOption import com.atlassian.jira.issue.MutableIssue import com.atlassian.jira.issue.fields.CustomField import java.sql.Timestamp CustomField customField = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("custom field name 1") if(customField == null) return "no such custom field" //Not requared into a postfunction MutableIssue issue = ComponentAccessor.getIssueManager().getIssueObject("ZVER-10") if(issue == null) return "an issue not found" //Here we set requred date Calendar dateToSet = Calendar.getInstance(); //here you could get local time on user machine. But I am not sure issue.setCustomFieldValue(customField, new Timestamp(dateToSet.getTimeInMillis())) //Here we do the update. Not requared into postfunction ComponentAccessor.getIssueManager().updateIssue(ComponentAccessor.getJiraAuthenticationContext().getUser().getDirectoryUser(), issue, EventDispatchOption.ISSUE_UPDATED, false)
I think that this code should set local time, but I am not sure. Try it.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
This code should be inserted into Scripted postfunction provided by ScriptRunner Plugin.
For test properties you can use ScriptConsole. See this:https://answers.atlassian.com/questions/32982259
In this case you should specify an issue (see line MutableIssue issue = ComponentAccessor.getIssueManager().getIssueObject(
"ZVER-10"
)
)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Do i delete all bits of code that have //not required into post function ?
So like this:
import com.atlassian.jira.component.ComponentAccessor import com.atlassian.jira.event.type.EventDispatchOption import com.atlassian.jira.issue.MutableIssue import com.atlassian.jira.issue.fields.CustomField import java.sql.Timestamp CustomField customField = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("customfield_11520") if(customField == null) return "no such custom field" //Here we set requred date Calendar dateToSet = Calendar.getInstance(); //here you could get local time on user machine. But I am not sure issue.setCustomFieldValue(customField, new Timestamp(dateToSet.getTimeInMillis()))
Also do i just use a normal date picker custom field? or do i need to use a scripted field or calculated date/time field?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I managed to get it working however it does not pull the current users local machine date, i believe it is pulling the server date as i am in australia so it should of set the value to 22/03/2016 however it set the date to 21/03/2016
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Try to check date/time on your server.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
yeah its pulling the sever local date i believe, i need it to pull the current users actual machine time.. or thinking about it do i need to incorporate the users current timezone profile at all?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
If you use this code into a servlet you could try to send current time from local machine using javascript. This could by stored as a param into URL.
For examle: ......?curtime=08:32am
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Discover how Atlassian is revolutionizing service management with cutting-edge solutions for AI-powered support, HR Service Management, or DevOps connectivity.
Register here ⬇️Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.