Hello,
There is the task to modify monthly the filter like "issuetype = Bug AND created >= 2022-10-20", that is instead of 10 some variable should be used.
To schedule the update, I'm going to use the Jira Automation.
Appreciate any help.
BR,
Ivan
I can help with a groovy script to modify a filter.
But I'm not sure this business case necessarily requires it.
If for example, you're interested in all issues created in the previous month you can use strict JQL with relative date functions:
created > StartOfMonth(-1) and created < EndOfMonth(-1)
Right now, this shows all issues created in August. On October 1 it will start to show all issues created in the month of September
If you need "exactly" issues created after the 20th of the month... that won't work. But you could have issues created since 10days before the start of the month (that will be after 20th or 21st)
created > StartOfMonth(-10d)
Here is a short script to retrieve and update a filter:
import com.atlassian.jira.bc.issue.search.SearchService
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.search.SearchRequestManager
def searchRequestManager = ComponentAccessor.getComponent(SearchRequestManager)
def searchService = ComponentAccessor.getComponent(SearchService)
def currentUser = ComponentAccessor.jiraAuthenticationContext.loggedInUser
def filterId = 123456L
def monthVariable = 10
def filter = searchRequestManager.getSearchRequestById(filterId)
def jql = """issuetype = Bug AND created >= 2022-$monthVariable-20"""
def parseResult = searchService.parseQuery(currentUser, jql)
assert parseResult.valid: parseResult.errors
filter.query = parseResult.query
searchRequestManager.update(currentUser, filter)
User executing the script must have permissions to edit the filter.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Peter-Dave,
I see your doubt and share it - yes, it's not a big deal once a month to change a filter just manually. Maybe because of it I haven't found any examples of this kind to start from. But they want some automation.
Regarding the query, it makes sense in format like created >= 2022-XX-20, as they need tickets since some date till a date when they require it. It's not always the end of a month.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks a lot, Peter-Dave.
I'll try it. Probably instead of monthVariable = 10 anything like now.getMonth() to be used, as the script will run by schedule?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
There is no "now" in groovy.
You can do
new Date().getMonth() + 1
+1 because the getMonth returns the zero-base month index
You can also use:
import java.text.SimpleDateFormat
new SimpleDateFormat('M').format(new Date())
Or to get "09"
import java.text.SimpleDateFormat
new SimpleDateFormat('MM').format(new Date())
Or even get your full date for the current year:
import java.text.SimpleDateFormat
new SimpleDateFormat('YYYY-MM-20').format(new Date())
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Then if using full date calculation, would it look like this?
def fullDataVariable = SimpleDateFormat('YYYY-MM-20').format(new Date())
//
def jql = """issuetype = Bug AND created >= $fullDataVariable"""
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You need to create an instance of the SimpleDateFormat
So either
def formattedDate = new SimpleDateFormat('YYYY-MM-20').format(new Date())
def jql = """issuetype = Bug AND created >= "$formattedDate" """
Or
def formatter = new SimpleDateFormat('YYYY-MM-20)
def formattedDate = formatter.format(new Date())
def jql = """issuetype = Bug AND created >= "$formattedDate" """
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I'm new to confluence APIs.
Please, can you tell me which dependencies to use?
to resolve this.
import com.atlassian.confluence.spaces.SpaceManager
I included most of the confluence libs but, they never got resolved.
I need the Gradle dependency line like this or maven XML of course.
implementation group: 'com.atlassian.confluence', name: 'confluence-rest-client', version: '8.0.0-m012'
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Ivan D
Why don't you use scriptrunner's Jobs?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Alex,
It's not essential how to schedule the execution. I'm more familiar with the automation and it has such action as running groovy scripts.
The main concern for me is the script.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.