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

Fabio S July 25, 2017

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

0 votes
Gaston Valente
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 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

 

 

Fabio S July 25, 2017

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
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 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
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 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 

0 votes
Fabio S July 25, 2017

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"
}

Suggest an answer

Log in or Sign up to answer