Hiding Date Fields Using ScriptRunner in 7.12.1

Sir Charles Amante November 20, 2018

Is it possible to dynamically hide date fields in the view screen now that they're all moved to the new date panel? Via ScriptRunner, PowerScripts or any other means? We currently use ScriptRunner, so that's the preference but we're open to any solution.

I can hide any dates just fine in create\edit screens. No matter what I try I can't seem to effectively hide them in the date panel. 

The one exception is if I hide them in field configuration. That does the trick, but then I can't set values for fields hidden in such a way. Why would I want to set the value for a hidden field you ask? Well, because we have a hard requirement for times in our due dates and for some bizarre reason Atlassian finds this unacceptable. I have the value from a custom due date field automatically copied into the system due date field to resolve this. However, now I have two due dates displayed in the date panel because you can't hide a date that has a value... 

Halp?

1 answer

1 accepted

0 votes
Answer accepted
Sir Charles Amante November 20, 2018

This solution uses ScriptRunner.

"customfield_10857" is a custom DateTime field named "Due Date" that's added to the Create\Edit\View screens to replace the system Due Date. 

The system Due Date field is hidden in the Field Configuration for this issue type and then populated via a Post-Function on the Create transition:


import java.sql.Timestamp
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue

Calendar dueDate = Calendar.getInstance()
dueDate.setTime( (Date) issue.getCustomFieldValue(ComponentAccessor.getCustomFieldManager().getCustomFieldObject("customfield_10857")))

issue.setDueDate (new Timestamp (dueDate.getTime().getTime()))

…and via a Listener for the Issue Update event: 

import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.UpdateIssueRequest
import java.sql.Timestamp
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.event.type.EventDispatchOption

Issue topIssue = event.issue
MutableIssue issue = ComponentAccessor.getIssueManager().getIssueObject(topIssue.getKey())

Calendar dueDate = Calendar.getInstance()
dueDate.setTime( (Date) issue.getCustomFieldValue ComponentAccessor.getCustomFieldManager().getCustomFieldObject("customfield_10857")))

issue.setDueDate (new Timestamp (dueDate.getTime().getTime()))

ComponentAccessor.getIssueManager().updateIssue(
        ComponentAccessor.jiraAuthenticationContext.getLoggedInUser()
       ,issue
       ,UpdateIssueRequest.builder().eventDispatchOption(EventDispatchOption.ISSUE_UPDATED).sendMail(false).build()
)

 

Suggest an answer

Log in or Sign up to answer