I have a scripted field that gets the date an issue was closed using this code:
import com.atlassian.jira.ComponentManager def componentManager = ComponentManager.getInstance() def changeHistoryManager = componentManager.getChangeHistoryManager() changeHistoryManager.getChangeItemsForField(issue, "status").find {it.toString == "Closed"}?.getCreated()
Which works OK as a text field but I want to use it as a date time field - so it apears with all the other dates on the screen.
I just get:
$datePickerFormatter.format($value)
You should perform to steps - convert string to Date formate and then convert date to disirable string format. Here is code:
import com.atlassian.jira.component.ComponentAccessor import java.text.SimpleDateFormat return (new SimpleDateFormat("yyyy-MM-dd")) // for desirable format .format(new SimpleDateFormat("yyyy/MM/DD")) //for format returned form change history .parse(ComponentAccessor.getChangeHistoryManager().getChangeItemsForField(issue, "status").find {it.toString == "Closed"}?.getCreated())
Thanks for your help but I just get:
java.lang.IllegalArgumentException: Cannot format given Object as a Date
import com.atlassian.jira.ComponentManager import java.text.SimpleDateFormat def componentManager = ComponentManager.getInstance() def changeHistoryManager = componentManager.getChangeHistoryManager() def closed = changeHistoryManager.getChangeItemsForField(issue, "status").find {it.toString = "Closed"}?.getCreated().toString() def frmt = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(closed) return new SimpleDateFormat("yyyy-MM-dd").format(frmt)
But that only works as a text field not a date time.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Try this one:
import com.atlassian.jira.ComponentManager import java.text.SimpleDateFormat def componentManager = ComponentManager.getInstance() def changeHistoryManager = componentManager.getChangeHistoryManager() String closed = changeHistoryManager.getChangeItemsForField(issue, "status").find {it.toString = "Closed"}?.getCreated().toString() Date frmt = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(closed) return new SimpleDateFormat("yyyy-MM-dd").format(frmt)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Nope still get:
$datePickerFormatter.format($value)
when I try to use it as a datetime picker.
Thanks for the ideas though.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I had the same problem. Make sure to set the correct search (a date searcher) on the scripted field. That fixed my problems.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.