Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,298,677
Community Members
 
Community Events
165
Community Groups

Archive Issue using a post-function

I am tying to setup a workflow transition to archive issues. To do this I am trying to use a ScriptRunner Post Function script.

import com.atlassian.jira.issue.archiving.ArchivedIssueService
import com.atlassian.jira.issue.archiving.ArchivedIssueService.ValidationResult
import com.atlassian.jira.issue.archiving.ArchivedIssueService.ArchivingResult
import com.atlassian.jira.component.ComponentAccessor
import org.apache.log4j.Logger
import org.apache.log4j.Level

def log = Logger.getLogger("com.wmic.archive")
log.setLevel(Level.DEBUG)

ArchivedIssueService archivedIssueService = ComponentAccessor.getComponent(ArchivedIssueService.class)

ValidationResult validationResult = archivedIssueService.validateArchiveIssue(ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser(), issue.getKey(), true)

if (validationResult.isValid())
log.debug("Archiving issue ${issue.getKey()}: ${archivedIssueService.archiveIssue(validationResult).isValid()}")
else
log.error("Failed to archiving issue ${issue.getKey()}: Validation Failed")
false

 

Everything logs as though it is succeeding. archivedIssueService.archiveIssue(validationResult).isValid() returns true. However the issue remains unarchived. What am I doing wrong?

Thanks in advance,
Carl

1 answer

Hi @Carl Adolfson ,

did you find a solution for this?

I first tried to use IssueManager.archiveIssue(). Result is the same as your code but not that save as we have no validation.

I can't find the built in post function in my instance (https://docs.adaptavist.com/sr4js/latest/features/workflows/post-functions/built-in-post-functions/archive-this-issue)

In console both custom scripts are working.

Then I tried to set up an listener, but it's the same result. Success is logged but issue isn't archived.

In the issue history I see that issue was archived but I think that Jira isn't done with reindexing and is saving the unarchived issue back to database after the attempt to archive it.

I will now configure the archiving issues job (https://docs.adaptavist.com/sr4js/latest/features/jobs/built-in-jobs/issue-archiving-job-data-center)

Regards

Suggest an answer

Log in or Sign up to answer
TAGS

Community Events

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

Find an event

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

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you