The Atlassian Community can help you and your team get more value out of Atlassian products and practices.
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 ))
}
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.
Hello everyone, Hope everyone is safe! A few months ago we posted an article sharing all the new articles and documentation that we, the AMER Jira Service Management team created. As mentioned ...
Connect with like-minded Atlassian users at free events near you!
Find an eventConnect with like-minded Atlassian users at free events near you!
Unfortunately there are no Community Events near you at the moment.
Host an eventYou're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.