Page tree

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

场景:根据jql语句,查询工时,然后删除,或者变更

Code Block
def projectKey = 'TEST'
def startDate = '2020/12/01'
def endDate = '2021/01/09'
queryText = "worklogDate >= '" +startDate+ "' AND worklogDate < '" + endDate + "' AND project = " + projectKey
//Executre the query
try{
query = jqlQueryParser.parseQuery(queryText)
}catch(Exception ex){
log.info("Error executing the query: " + queryText)
}

def search = searchService.search(user, query, PagerFilter.getUnlimitedFilter())

//Iterate the issues 
search.results.each { documentIssue ->
MutableIssue issue = issueManager.getIssueObject(documentIssue.id)

def workLogManager = ComponentAccessor.getWorklogManager()
def logsForIssue = workLogManager.getByIssue(issue)

//Iterate the worklog of the issue 
for(Worklog worklog : logsForIssue)
{
def date = new SimpleDateFormat("yyyy/MM/dd").format(worklog.getCreated())
if((date >= startDate) && (date < endDate)){
//Delete the worklog
workLogManager.delete(worklog.getAuthorObject(), worklog, null, true)
}
}
}