Use API with ScriptRunner
You can use API from VERSION 1.14.0+
Creating Listeners in ScriptRunner for Alfresco Link Events
By using Listener of ScriptRunner, you can add custom processing to the event of Alfresco link (Linking and Unlinking) as a trigger.
Go to Settings > Manage Apps > Listeners > Create Listener.
Click Custom Listener.
Complete the following fields:
Project(s) - Select the project or projects for which you want to create the listener.
Events - Select one or more of the available Alfresco events (jp.ricksoft.plugins.alfresco.event.DOCUMENT_LINK, jp.ricksoft.plugins.alfresco.event.DOCUMENT_UNLINK).
Inline Script - Add your script to the text box. You can copy/paste pre-made scripts from the following.
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.event.issue.IssueEvent
import com.atlassian.jira.event.type.EventType
import com.atlassian.jira.event.type.EventTypeManager
import org.apache.log4j.Logger
import org.apache.log4j.Level
def log = Logger.getLogger("jp.ricksoft.plugins")
log.setLevel(Level.INFO)
EventTypeManager eventTypeManager = ComponentAccessor.getEventTypeManager()
EventType eventType = eventTypeManager.getEventType(event.getEventTypeId())
IssueEvent issueEvent = (IssueEvent) event;
Issue issue = issueEvent.getIssue()
Map<String, Object> params = issueEvent.getParams()
def documentLinkRequests = params.get("documentLinkRequest")
for (def documentLinkRequest : documentLinkRequests) {
String objectId = documentLinkRequest.getObjectId()
String objectName = documentLinkRequest.getObjectName()
log.info("eventName [${eventType.name}], issueKey [${issue.key}], objectId [${objectId}], objectName [${objectName}]")
}
[jp.ricksoft.plugins] issue [AAA-1], name [jp.ricksoft.plugins.alfresco.event.DOCUMENT_UNLINK], objectId [7bb7bfa8-997e-4c55-8bd9-2e5029653bc8], objectName [inv I200-189.png]
[jp.ricksoft.plugins] issue [AAA-1], name [jp.ricksoft.plugins.alfresco.event.DOCUMENT_LINK], objectId [7bb7bfa8-997e-4c55-8bd9-2e5029653bc8], objectName [inv I200-189.png]
Creating Listeners in ScriptRunner for Clone Issue with Alfresco Link
By using Listener of ScriptRunner, when you clone a Jira issue, you can also clone the Alfresco link (Linking and Unlinking) linked to the Jira issue.
Go to Settings > Manage Apps > Listeners > Create Listener.
Click Custom Listener.
Complete the following fields:
Project(s) - Select the project or projects for which you want to create the listener.
Events - Select IssueLinkCreatedEvent.
Inline Script - Add your script to the text box. You can copy/paste pre-made scripts from the following.
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.issue.link.IssueLinkCreatedEvent
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.link.IssueLinkManager
import com.atlassian.jira.issue.link.IssueLink
import com.atlassian.jira.user.ApplicationUser
import com.onresolve.scriptrunner.runner.customisers.WithPlugin
import com.onresolve.scriptrunner.runner.customisers.PluginModule
import jp.ricksoft.plugins.alfresco.ao.service.*
import jp.ricksoft.plugins.alfresco.ao.entity.*
import jp.ricksoft.plugins.alfresco.rest.*
import org.apache.log4j.Logger
import org.apache.log4j.Level
Logger log = Logger.getLogger("jp.ricksoft.plugins")
log.setLevel(Level.DEBUG)
// https://scriptrunner.adaptavist.com/4.3.5/jira/scripting-other-plugins.html
@WithPlugin("jp.ricksoft.plugins.alfresco-for-jira")
@PluginModule DocumentLinkService documentLinkService
Class documentLinkServiceClass = ComponentAccessor.getPluginAccessor().getClassLoader().loadClass("jp.ricksoft.plugins.alfresco.ao.service.DocumentLinkService")
documentLinkService = (DocumentLinkService) ComponentAccessor.getOSGiComponentInstanceOfType(documentLinkServiceClass)
IssueLinkManager issueLinkManager = ComponentAccessor.getIssueLinkManager()
// https://scriptrunner.adaptavist.com/5.1.6/jira/releases/current-release.html
// https://docs.atlassian.com/software/jira/docs/api/7.6.1/com/atlassian/jira/event/issue/link/IssueLinkCreatedEvent.html
IssueLink issueLink = event.issueLink
ApplicationUser currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
if (currentUser == null) {
return
}
if (!"Cloners".equals(issueLink.issueLinkType.name)) {
return
}
Issue destinationIssue = issueLink.getDestinationObject()
log.debug("Clone destination Issue:" + destinationIssue)
Issue sourceIssue = issueLink.getSourceObject()
log.debug("Clone Source Issue:" + sourceIssue)
List<DocumentLinkResource.DocumentLinkRequestObject> alfrescoLinks = documentLinkService.find(destinationIssue).collect { entity ->
Long projectId = entity.getProjectId()
Long issueId = entity.getIssueId()
String objectId = entity.getObjectId()
String authorKey = entity.getAuthorKey()
Date created = entity.getCreated()
log.debug("Source Alfresco Link projectId:" + projectId + " issueId:" + issueId + " objectId:" + objectId + " authorKey:" + authorKey + " created:" + created)
return new DocumentLinkResource.DocumentLinkRequestObject(objectId, "")
};
if (alfrescoLinks.isEmpty()) {
return
}
documentLinkService.save(sourceIssue, alfrescoLinks, currentUser)
Use Console in ScriptRunner for Migrating Alfresco Link to Alfresco
Before using the Relationships, You can migrate the existing Alfresco links (Linking and Unlinking) to Jira tickets. The Relationships must be enabled (Install Guide for Alfresco Association plugin) before running this migration script.
Go to Settings > Manage Apps > Console.
Complete the following fields:
Script - Add your script to the text box. You can copy/paste pre-made scripts from the following.