Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Why am I getting an error when trying to delete all future events in a calendar?

Stephanie Saad
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
October 29, 2017

Error(s) occurred.

An error occurred while trying to delete event 20171010T225744Z--76744798@confluence.abc-dev.net.au.

Every time I try to delete future instances of two reoccurring events, I am getting the above error. 

I am able to delete each individual instance of the event, however this will take me forever to do as I originally set up the event as reoccurring with no end dates.

Anyone have any clues? 

 

1 answer

1 accepted

Suggest an answer

Log in or Sign up to answer
0 votes
Answer accepted
Alex Koxaras -Relational-
Community Champion
November 15, 2022

Hi @Diana Gorv 

I don't know if you've pasted the code exactly as you have written it on the workflow PF, but you have three typos:

import com.atlassian.jira.event.type.EventDisptachOption
import com.atlassian.jira.bc.user.sedarch.UserSearchService
ComponentAccessor.getIsuseManager().updateIssue(loggedInUser,issue,EventDispatchOption.Issue_UPDATED, false)

When I corrected these error your PF (I ran it on the console, so I made a few changes) worked, BUT it needed some changes. As I said, running the code on the console like the following worked fine. However, if you want to test it on your instance, change the "SP-1" with an issue of your instance. This was just for test

import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.bc.user.search.UserSearchParams
import com.atlassian.jira.bc.JiraServiceContextImpl
import com.atlassian.jira.bc.user.search.UserSearchService
import com.atlassian.jira.application.ApplicationAuthorizationService
import com.atlassian.jira.issue.MutableIssue

def versionManager = ComponentAccessor.getVersionManager()
def issueManager = ComponentAccessor.getIssueManager()
def issue = issueManager.getIssueObject("SP-1") as MutableIssue
def project = issue.getProjectObject().getId()
def version = versionManager.getVersionsUnreleased(project, false)
def resolution = issue.getResolution()

//def earliestUnreleasedVersion = versionManager.updateIssueFixVersions(issue,version) THIS LINE WILL ADD ALL VERSIONS TO YOUR ISSUE

//bypass user permissions so fix version can be set
UserSearchParams.Builder paramBuilder = UserSearchParams.builder()
.ignorePermissionCheck(true)

def loggedInUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def jiraServiceContext = new JiraServiceContextImpl(loggedInUser)
def applicationAuthorizationService = ComponentAccessor.getComponent(ApplicationAuthorizationService)
def users = ComponentAccessor.getComponent(UserSearchService).findUsers(jiraServiceContext, "",paramBuilder.build())

try {
if (loggedInUser == users && resolution != 'Unresolved'){
issue.setFixVersions([version.first()])
ComponentAccessor.issueManager.updateIssue(loggedInUser, issue, EventDispatchOption.ISSUE_UPDATED, false)
log.warn([version.first()])
}
} catch (Exception e) {}

Now, the following line you have, and I commented out, was adding all versions to the issue:

def earliestUnreleasedVersion = versionManager.updateIssueFixVersions(issue,version) 

 

I would place your script on a workflow PF and not on a listener, and most likely your code (without testing it on a workflow) should look like this:

import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.bc.user.search.UserSearchParams
import com.atlassian.jira.bc.JiraServiceContextImpl
import com.atlassian.jira.bc.user.search.UserSearchService
import com.atlassian.jira.application.ApplicationAuthorizationService

def versionManager = ComponentAccessor.getVersionManager()
def issueManager = ComponentAccessor.getIssueManager()
def project = issue.getProjectObject().getId()
def version = versionManager.getVersionsUnreleased(project, false)
def resolution = issue.getResolution()

//bypass user permissions so fix version can be set
UserSearchParams.Builder paramBuilder = UserSearchParams.builder()
.ignorePermissionCheck(true)

def loggedInUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def jiraServiceContext = new JiraServiceContextImpl(loggedInUser)
def applicationAuthorizationService = ComponentAccessor.getComponent(ApplicationAuthorizationService)
def users = ComponentAccessor.getComponent(UserSearchService).findUsers(jiraServiceContext, "",paramBuilder.build())

try {
if (loggedInUser == users && resolution != 'Unresolved'){
issue.setFixVersions([version.first()])
ComponentAccessor.issueManager.updateIssue(loggedInUser, issue, EventDispatchOption.ISSUE_UPDATED, false)
log.warn([version.first()])
}
} catch (Exception e) {}

Try it and let me know if that works!

Diana
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 Champions.
November 15, 2022

Hi @Alex Koxaras -Relational- thank you for catching my typos, I had to manually type it in since the script is on an air-gapped environment that I can't copy and paste :)

This script works! Thank you so much!!

A couple of notes for future viewers in case they still have trouble.

  • I forgot to clear an old transition screen that's requesting for a Fix Version. 
  • Even if I did kept the transition screen and tried to change the Fix Version to a later version, the post-function script above does automatically set to the correct earliestUnreleasedVersion
  • It's possible the permission check might not be needed. I checked by logging in as another user, and was able to transition an issue to Done and see the Fix Version is auto set correctly.

One last question, if a user had placed 2 Fix Versions, can they both be cleared and then set Fix Version? When I tested by editing an issue to be 23.Q3 and 23.Q4, pushed issue to done, the 2 Fix Version stayed. 

I tried adding:

issue.setFixVersions(null)

But it didn't work. If not, I can still accept this an an answer.

 

Thanks!

Alex Koxaras -Relational-
Community Champion
November 15, 2022

So you want something to clear the version you mean?

Alex Koxaras -Relational-
Community Champion
November 15, 2022

Try 

issue.setFixVersions([]);
Diana
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 Champions.
November 16, 2022

Yes! I had to include an || for my If statement to capture if a user had placed more than 1 fix version by mistake

if ((issue.fixVersions.size()>1) || (loggedInUser == users && resolution != 'Unresolved')){
issue.setFixVersions([]);
issue.setFixVersions([version.first()]);
ComponentAccessor.issueManager.updateIssue(loggedInUser, issue, EventDispatchOption.ISSUE_UPDATED, false);
log.warn([version.first()])
}
TAGS
AUG Leaders

Atlassian Community Events