Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,361,727
Community Members
 
Community Events
168
Community Groups

Update Date & Time field based on Checkbox

Edited

Hi,

I am looking to update a custom Date & Time Field based on if a user clicks the "Yes" option in a Checkbox field.

I tried Project Automation but we have the free version and not all features are available.

I thought the alternative may be a scripted custom Date & Time Field that updates when the choice is made?

I have used this code previously when an issue is created but unsure how to modify the code for a checkbox field?

 

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
 
def issue = event.issue
 
// the name of the custom field to update
final customFieldName = 'Created Date & Time'
 
// the new value of the field
final newValue = issue.created
 
def customFieldManager = ComponentAccessor.customFieldManager
 
def customField = customFieldManager.getCustomFieldObjects(issue).findByName(customFieldName)
assert customField : "Could not find custom field with name $customFieldName"
 
customField.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(customField), newValue), new DefaultIssueChangeHolder())
Any help is appreciated
Thanks.

2 answers

1 accepted

0 votes
Answer accepted

This script shows you how to work with all sorts of custom fields.  Note that check-boxes work the same way as multi-select lists!

I think you're probably right about using a scripted field - this would stop the users entering the wrong data into it.  With a scripted field, the two tricks you need to know when coding it are 1) Remember to set the output template to the appropriate type - you're calculating a date, so I'd use a date/time template, 2) the value of the scripted field is what the script "returns", you do not have to set a value in the field, just calculate and return it. 

0 votes
Vikrant Yadav Community Leader Aug 15, 2022

Hi @Drishti Maharaj  May i know for which event you are trying to update Date Time custom field

If you are looking to set field value for Issue Created event then i suggest you use custom Date Time field instead of scripted field and apply scripted post function, it will set value if checkbox is having value "Yes" . 

If you are looking to update Date Time field for Issue Updated event then try to apply Scripted Listener, which will set value when user select "Yes" value in  checkbox field.

 

Thanks

V Y

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Jira

Online AMA this week: Your project management questions answered by Jira Design Lead James Rotanson

We know that great teams require amazing project management chops. It's no surprise that great teams who use Jira have strong project managers, effective workflows, and secrets that bring planning ...

211 views 1 6
Read article

Atlassian Community Events