Get the Date/Time When a Custom Field Was Set to "Yes"

Hello,

I have a custom "Field A" that needs to be populated with the date/time when another custom "Field B" was set to "Yes".

I need to create a script that:

  1. Runs a JQL to filter all the issues that have "Field B" set to "Yes"
  2. Get the date/time when the user selected "Yes"
  3. Add this information to "Field A"

Any ideas?

2 answers

This widget could not be displayed.

This is what I have so far:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.search.SearchProvider
import com.atlassian.jira.jql.parser.JqlQueryParser
import com.atlassian.jira.web.bean.PagerFilter

def jqlQueryParser = ComponentAccessor.getComponent(JqlQueryParser.class)
def searchProvider = ComponentAccessor.getComponent(SearchProvider.class)
def issueManager = ComponentAccessor.getIssueManager()
def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def query = jqlQueryParser.parseQuery("myJQL")
def results = searchProvider.search(query, user, PagerFilter.getUnlimitedFilter())

results.getIssues().each {
//code to get date/time when "Field B" was set to "Yes"
//code to add the date/time to "Field A"
}
This widget could not be displayed.
Gaston Valente Community Champion Jul 25, 2017

Fabio,

I think there's no direct way, you need to query the rest api for the changelog of every issue, check the modifications and derive the date from this information.

then you can add the date to another field for querying

 

 

Thanks Gaston,

In this case you would do everything with REST API, get the information and update the tickets? Or you would get the information with REST API and update the fields with ScriptRunner?

Regards.

Gaston Valente Community Champion Jul 25, 2017

Hi,

it depends on your needs, for example if I need to record the first date that the field changed:

 

  1. create a service in script runner to query by jql all the issues with the field in yes and the date empty
  2. loop the issues from the result set and update the date field with the changelog

 

Gaston Valente Community Champion Jul 25, 2017

If you need to get the date value right away I'll do the same but with a listener and only the current issue 

Suggest an answer

Log in or Sign up to answer
Atlassian Summit 2018

Meet the community IRL

Atlassian Summit is an excellent opportunity for in-person support, training, and networking.

Learn more
Community showcase
Posted Wednesday in New to Jira

Are you planning to trial, or are currently trialling Jira Software? - We want to talk to you!

Hello! I'm Rayen, a product manager at Atlassian. My team and I are working hard to improve the trial experience for Jira Software Cloud. We are interested in   talking to 20 people planning t...

97 views 1 0
Join discussion

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you