How to add remotissuelinks to issue

Arun April 26, 2023

// Get the Jira issue manager
def issueManager = ComponentAccessor.getIssueManager()

// Get the Jira issue
def issue = issueManager.getIssueObject(issueKey)

// Create a RemoteIssueLinkBuilder object and set its properties
def remoteLinkBuilder = new RemoteIssueLinkBuilder()
remoteLinkBuilder.url(remoteUrl)
remoteLinkBuilder.title(remoteTitle)

// Create the RemoteIssueLink object
def remoteLink = remoteLinkBuilder.build()

// Add the remote link to the issue
issue.getRemoteIssueLinks().add(remoteLink)

// Save the issue
issueManager.updateIssue(ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser(), issue, EventDispatchOption.DO_NOT_DISPATCH, false)

16 answers

1 accepted

0 votes
Answer accepted
Arun May 12, 2023
import com.onresolve.scriptrunner.runner.customisers.WithPlugin
import com.onresolve.scriptrunner.runner.customisers.PluginModule
import com.riadalabs.jira.plugins.insight.channel.external.api.facade.ObjectFacade
import com.riadalabs.jira.plugins.insight.channel.external.api.facade.ObjectTypeFacade
import com.riadalabs.jira.plugins.insight.channel.external.api.facade.ObjectTypeAttributeFacade
@WithPlugin('com.riadalabs.jira.plugins.insight')
@PluginModule ObjectFacade objectFacade
@PluginModule ObjectTypeFacade objectTypeFacade
@PluginModule ObjectTypeAttributeFacade objectTypeAttributeFacade
0 votes
Arun May 26, 2023

import com.atlassian.jira.issue.IssueFieldConstants
import com.onresolve.jira.groovy.user.FieldBehaviours
import groovy.transform.BaseScript

@BaseScript FieldBehaviours fieldBehaviours

final String fieldName = 'TextField'

// get field by name and hide it
getFieldByName(fieldName).setHidden(true)

0 votes
Arun May 26, 2023


def fieldLayoutItem = ComponentAccessor.getFieldLayoutManager().getFieldLayout(issue).getFieldLayoutItem(field)
def visibility = fieldLayoutItem.getVisibility()
def userUtil = ComponentAccessor.getUserUtil()
def loggedInUser = userUtil.getUserByName(username)
fieldManager.updateCustomField(field.getId(), field.name, field.description, visibility, false, null)

0 votes
Arun May 15, 2023

import com.atlassian.jira.component.ComponentAccessor import com.atlassian.jira.issue.Issue // Retrieve all issues in Jira def issueManager = ComponentAccessor.issueManager def allIssues = issueManager.getIssueObjects() // Log information about the script execution for each issue allIssues.each { Issue issue -> log.warn("Script triggered for issue: ${issue.key}") log.warn("Script details: Your script details here") }

0 votes
Arun May 12, 2023

def myObject = InsightUtils.getObjectByKey('')
String value = InsightUtils.getAttributeValueFromDotNotation(myObject, "")


//
// Read attributs
//

Map myMap = InsightUtils.getAllAttributesAsKeyValuePairs(myObject)
myMap.each{ attribut, valeur -> log.warn "${attribut} : ${valeur}" }

0 votes
Arun May 9, 2023

s

0 votes
Arun May 1, 2023

def delimiter = ":"

def delimiterIndex = jsmid.indexOf(delimiter)

if (delimiterIndex != -1 && delimiterIndex < jsmid.size() - 1) {
def characterAfterDelimiter = jsmid[delimiterIndex + 1]
println(characterAfterDelimiter) // Output: " "
}

0 votes
Arun May 1, 2023

import com.onresolve.scriptrunner.runner.rest.common.CustomEndpointDelegate import groovy.json.JsonSlurper // Replace the URL and issue key with your own def url = "https://your-jira-instance.atlassian.net/rest/api/3/issue/ISSUE-KEY" def response = new CustomEndpointDelegate().get(url) // Parse the response as JSON def json = new JsonSlurper().parseText(response.getEntity(String.class)) // Access the fields of the issue def issueKey = json.key def summary = json.fields.summary def description = json.fields.description

0 votes
Arun May 1, 2023
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue

def issueManager = ComponentAccessor.getIssueManager()

// Get the issue using its key
Issue issue = issueManager.getIssueObject("JSM-123")

// Do something with the issue object
if (issue) {
    log.debug("Issue summary: ${issue.summary}")
    log.debug("Issue description: ${issue.description}")
} else {
    log.debug("Could not find issue with key JSM-123")
}
0 votes
Arun April 30, 2023

import com.atlassian.jira.event.issue.IssueEvent def log = LoggerFactory.getLogger("com.example.listener") def issueEvent = event as IssueEvent def issue = issueEvent.issue def issueKey = issue.key log.debug("Issue ${issueKey} was updated.")

0 votes
Arun April 30, 2023

def issueKey = "" // replace with the key of the issue you want to link to
def url = "" // replace with the URL of the external issue
def title = "" // replace with the title of the external issue

def issueLinkService = ComponentAccessor.getComponent(RemoteIssueLinkService)
def issue = ComponentAccessor.getIssueManager().getIssueObject(issueKey)

def remoteIssueLinkBuilder = new RemoteIssueLinkBuilder()
.issueId(issue.id)
.url(url)
.title(title)
.globalId("")
.applicationName("")
.relationship("")

def remoteIssueLink = remoteIssueLinkBuilder.build()
issueLinkService.createRemoteIssueLink(ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser(), issue, remoteIssueLink)

0 votes
Arun April 28, 2023

s

0 votes
Arun April 27, 2023

a

Arun April 28, 2023

s

0 votes
Arun April 27, 2023

c

0 votes
Arun April 27, 2023

import com.onresolve.scriptrunner.runner.customisers.WithPlugin
import com.atlassian.plugin.PluginAccessor
import com.atlassian.plugin.Plugin
import com.atlassian.plugin.ModuleDescriptor

@WithPlugin("org.codehaus.groovy.modules.http-builder:http-builder:0.7.1")

def pluginAccessor = ComponentAccessor.getPluginAccessor() as PluginAccessor
def plugin = pluginAccessor.getPlugin("org.codehaus.groovy.modules.http-builder:http-builder")
def moduleDescriptor = plugin.getModuleDescriptor("classpath:groovy/util/XmlSlurper")

if (moduleDescriptor) {
moduleDescriptor.enabled = true
}

0 votes
Arun April 27, 2023

import groovyx.net.http.HttpBuilder
import com.atlassian.jira.component.ComponentAccessor

// get the base URL of the Jira instance
def jiraBaseUrl = ComponentAccessor.getApplicationProperties().getString("jira.baseurl")

// create an HTTP builder with Basic Authentication using the logged-in user's credentials
def http = new HttpBuilder(jiraBaseUrl)
http.auth.basic(ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser().name,
ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser().password)

// make the API call to the Jira REST API
def response = http.get(path: '/rest/api/2/myself')
assert response.status == 200
def json = new groovy.json.JsonSlurper().parseText(response.getEntity().getContent())

// print the user's display name
println json.displayName

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
FREE
PERMISSIONS LEVEL
Site Admin
TAGS
AUG Leaders

Atlassian Community Events