Hello,
I am creating a post function that would record the date/time of a transition into the "Dev Done Test" field (if it's empty). I am trying to write a script that would do exactly that, but with no luck.
-------------------------------------------------------
import com.atlassian.jira.component.ComponentAccessor;
import java.sql.Timestamp;
import com.atlassian.jira.issue.Issue
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def cf = customFieldManager.getCustomFieldObjects(issue).find { it.name == "Dev Done Test" }
def cfValues = issue.getCustomFieldValue(cf)
def dateCf = customFieldManager.getCustomFieldObject("customfield_13300") // Date time fields require a Timestamp
if (cfValues['dateCf'] == null) {
issue.setCustomFieldValue(dateCf, new Timestamp((new Date()).time))
}
-------------------------------------------------------
Could you tell me what am I doing wrong, please?
You can try something like this:
import com.atlassian.core.util.DateUtils
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import java.sql.Timestamp;
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.MutableIssue
def issueManager = ComponentAccessor.getIssueManager()
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def changeHolder = new DefaultIssueChangeHolder()
def cf = customFieldManager.getCustomFieldObjects(issue).find { it.name == "Dev Done Test" }
def today = new Timestamp(new Date().time)
cf.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(cf), today),changeHolder)
Hello Fran,
thank you - as stated above, could you please tell me what should I add to make the script conditional? Ex. When the field is empty, to not modify it?
The use case is that we want this field filled during one transition OR at another one (but if the second, later one, happens, we don't want the contents of the field to be overwritten).
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
This should work:
if (issue.getCustomFieldValue(cf)==null){
def today = new Timestamp(new Date().time)
cf.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(cf),today),changeHolder)
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @licence
Why do you want to save transition date in a custom field? You can fetch it from the change history.
Start here: https://scriptrunner.adaptavist.com/latest/jira/recipes/scriptfields/dateOfFirstTransition.html
You can modify the code to look for the transition of your choice.
Ravi
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello Ravi,
our stakeholders store the information when the issue was in "Dev Done" status in a report of tens of issues, so it's a bit harder to browse issue by issue.
Thanks for the link. Could you please tell me what should I add to make the script conditional? Ex. When the field is empty, to not modify it?
The use case is that we want this field filled during one transition OR at another one (but if the second, later one, happens, we don't want the contents of the field to be overwritten).
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.