You're on your way to the next level! Join the Kudos program to earn points and save your progress.
Level 1: Seed
25 / 150 points
Next: Root
1 badge earned
Challenges come and go, but your rewards stay with you. Do more to earn more!
What goes around comes around! Share the love by gifting kudos to your peers.
Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!
Join now to unlock these features and more
Hi,
I want to copy the value of a Custom field Date picker on a Jira Service Management portal via a Behavior from an issue selected in an issue picker field.
The copy action works, but it is not displayed in the desired format.
How do I make sure it is displayed in the format dd-mm-yyyy?
Regards, Marco
current script:
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.IssueManager
def issueManager = ComponentAccessor.getIssueManager() as IssueManager
def issuePickerCustomFieldValue = getFieldById(getFieldChanged()).value
def relatedIssue = issueManager.getIssueByCurrentKey(issuePickerCustomFieldValue as String)
def EinddatumprojectCustomField = getFieldByName("Einddatum project")
def EinddatumprojectCustomFieldObject = customFieldManager.getCustomFieldObjectsByName("Einddatum project")[0]
def EinddatumprojectCustomFieldValue = (EinddatumprojectCustomFieldObject ? relatedIssue.getCustomFieldValue(EinddatumprojectCustomFieldObject) : null) as String
if (EinddatumprojectCustomFieldValue) {
EinddatumprojectCustomField.setFormValue(EinddatumprojectCustomFieldValue)
}
When you retrieve the value from your custom field, don't coerce the type to String:
def EinddatumprojectCustomFieldValue = (EinddatumprojectCustomFieldObject ? relatedIssue.getCustomFieldValue(EinddatumprojectCustomFieldObject) : null) as String
Because when you do that, you get the default format and you can't change it.
Instead, keep it as a Timestamp (the default data type for date in jira) so you can use the format method (with optional user timezone)
def EinddatumprojectCustomFieldValue = (EinddatumprojectCustomFieldObject ? relatedIssue.getCustomFieldValue(EinddatumprojectCustomFieldObject) : null) as java.sql.Timestamp
if (EinddatumprojectCustomFieldValue) {
EinddatumprojectCustomField.setFormValue(EinddatumprojectCustomFieldValue.format('dd-MM-yyyy'))
//to format date based on user tz instead of server tz
//def userTimeZone = ComponentAccessor.getComponent(com.atlassian.jira.timezone.TimeZoneManager).loggedInUserTimeZone
//EinddatumprojectCustomField.setFormValue(EinddatumprojectCustomFieldValue.format('dd-MM-yyyy',userTimeZone ))
}
@Peter-Dave Sheehan Thanks! It works!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
When you set the date to your field , try to do it like this:
myField.setFormValue(newVal.format("dd-mm-yyyy"))
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.