Hi,
I have a user requirement that utilizes the custom web item feature provided by scriptrunner. I have a custom field that needs to be added as a link, for example: The user enters something in the "Shipping #" custom field and after creation the Script Fragments piece adds a link in the operations-top-level. I need assistance with the link. Can someone please help. I cannot access the value of the custom field.
Hi Eric,
You cannot get the value of the scripted field in the link field. What you can do tho, is to create a rest endpoint that will redirect you somewhere esle, there is a similar example in the documentation.
So in your case you have to create a scripted rest endpoint and the script for this endpoint will be
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.sal.api.ApplicationProperties
import com.atlassian.sal.api.UrlMode
import com.onresolve.scriptrunner.runner.ScriptRunnerImpl
import com.onresolve.scriptrunner.runner.rest.common.CustomEndpointDelegate
import groovy.transform.BaseScript
import javax.ws.rs.core.MultivaluedMap
import javax.ws.rs.core.Response
@BaseScript CustomEndpointDelegate delegate
def applicationProperties = ScriptRunnerImpl.getOsgiService(ApplicationProperties)
def issueManager = ComponentAccessor.getIssueManager()
buttonLink(httpMethod: "GET") { MultivaluedMap queryParams ->
def issueId = queryParams.getFirst("issueId") as Long
if (!issueId)
return
def issue = issueManager.getIssueObject(issueId)
def cf = ComponentAccessor.customFieldManager.getCustomFieldObjectByName("TextFieldA")
def value = issue.getCustomFieldValue(cf)
def baseUrl = applicationProperties.getBaseUrl(UrlMode.ABSOLUTE)
Response.temporaryRedirect(URI.create("${baseUrl}/browse/$value")).build()
}
Now in the link field in your button you should vae something like
/rest/scriptrunner/latest/custom/buttonLink?issueId=${issue.id}
You just have to make sure that you select a setcionf for your itam that will have the issue object on it. For example
operations-top-level
Hope that does the trick.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.