Archive Issue using a post-function

Carl Adolfson November 26, 2019

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

0 votes
Erik Buchholz
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.
June 23, 2022

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

AisM January 4, 2024

Hi @Erik Buchholz  Did you by any chance have success with us. I tried using the inbuilt archive post function available within scriptrunner. The condition shows as success but the issues don't get archived. Even after trying to re-index the project, issue still aren't  archived. 

Erik Buchholz
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.
January 4, 2024

Hi @AisM ,

perhaps the post functions need to be in another order?

If it's not working with the built in function, I would suggest to ask the Adaptavist support.

Regards

PS: after working some time with the archiving job running in the night, I actually prefer this way, as the user can easier find the issue, if the decision for archiving was wrong.

AisM January 4, 2024

@Erik Buchholz  Thank you for the reply ! Actually I tried the above code instead of the scriptrunner build-in archive functionality.

Now, the code log shows as successful and the issue history shows as archived, but the actual issue doesn't appear archived. Really breaking my head over this.

Suggest an answer

Log in or Sign up to answer