I am trying to perform a REST endpoint with its corresponding web fragment but I am getting the error:
script function failed on issue: issue: SF-347, user: mouh, fieldId: __init__, file: <inline script>, edit behaviour: https://itrac-dev.eur.ad.sag/plugins/servlet/scriptrunner/admin/behaviours/edit/8, https://itrac-dev.eur.ad.sag/plugins/servlet/scriptrunner/admin/behaviours/edit/17, https://itrac-dev.eur.ad.sag/plugins/servlet/scriptrunner/admin/behaviours/edit/21
Here is my error log here below:
2022-08-16 20:39:37,512+0200 https-openssl-nio-443-exec-278 ERROR mouh 1239x60320x27 mu7qce 10.248.27.109 /rest/scriptrunner/behaviours/latest/validators.json [c.o.jira.behaviours.BehaviourManagerImpl] Script function failed on issue: issue: SF-347, user: mouh, fieldId: __init__, file: <inline script>, edit behaviour: https://itrac-dev.eur.ad.sag/plugins/servlet/scriptrunner/admin/behaviours/edit/8, https://itrac-dev.eur.ad.sag/plugins/servlet/scriptrunner/admin/behaviours/edit/17, https://itrac-dev.eur.ad.sag/plugins/servlet/scriptrunner/admin/behaviours/edit/21
2022-08-16 20:39:36,371+0200 https-openssl-nio-443-exec-278 WARN mouh 1239x60311x26 mu7qce 10.248.27.109 /browse/SF-347 [c.s.j.p.r.rest.api.MicroDashBoard] getiTracReleaseInfo for user "mouh" took 0 ms
2022-08-16 20:39:36,371+0200 https-openssl-nio-443-exec-278 WARN mouh 1239x60311x26 mu7qce 10.248.27.109 /browse/SF-347 [c.s.j.p.r.rest.api.MicroDashBoard] getiTracReleaseInfo for user "mouh" - "green" -0
2022-08-16 20:39:36,371+0200 https-openssl-nio-443-exec-278 WARN mouh 1239x60311x26 mu7qce 10.248.27.109 /browse/SF-347 [c.s.j.p.r.rest.api.MicroDashBoard] getiTracReleaseInfo for user "mouh" took 0 ms
2022-08-16 20:39:36,371+0200 https-openssl-nio-443-exec-278 WARN mouh 1239x60311x26 mu7qce 10.248.27.109 /browse/SF-347 [c.s.j.p.r.rest.api.MicroDashBoard] getiTracReleaseInfo for user "mouh" - "yellow" -0
2022-08-16 20:39:36,371+0200 https-openssl-nio-443-exec-278 WARN mouh 1239x60311x26 mu7qce 10.248.27.109 /browse/SF-347 [c.s.j.p.r.rest.api.MicroDashBoard] getiTracReleaseInfo for user "mouh" took 0 ms
2022-08-16 20:39:36,371+0200 https-openssl-nio-443-exec-278 WARN mouh 1239x60311x26 mu7qce 10.248.27.109 /browse/SF-347 [c.s.j.p.r.rest.api.MicroDashBoard] getiTracReleaseInfo for user "mouh" - "red" -0
I don't understand why I have this error my code is super simple. Here is the way in which I have created my web fragment:
This is a screenshot of the custom web item fragment I have created: This is the corresponding REST endpoint I have created:
I am specifying the file MounaBulkSummary.groovy to be the one containing the code for the REST endpoint.
Here is the content of the file MounaBulkSummary.groovy
import groovy.transform.BaseScript
import com.onresolve.scriptrunner.runner.rest.common.CustomEndpointDelegate
import javax.ws.rs.core.MultivaluedMap
import com.atlassian.jira.component.ComponentAccessor
import com.onresolve.scriptrunner.runner.ScriptRunnerImpl
import com.atlassian.sal.api.ApplicationProperties
import com.atlassian.sal.api.UrlMode
import javax.ws.rs.core.Response
import org.apache.log4j.Logger
def log = Logger.warn("atlassian-jira.log")
log.warn("MOUNA BULK")
@BaseScript CustomEndpointDelegate delegate
MounaBulkSummary(httpMethod: "GET") { MultivaluedMap queryParams ->
log.warn("MOUNA BULK")
def user = ComponentAccessor.jiraAuthenticationContext?.loggedInUser
def issue = ComponentAccessor.getIssueManager().getIssueObject(queryParams.getFirst("issueId") as Long)
def baseUrl = ScriptRunnerImpl.getOsgiService(ApplicationProperties).getBaseUrl(UrlMode.ABSOLUTE)
def redirectUrl = "https://secapps.eur.ad.sag:9888/FPIA/?iTrac=${issue.key}&reporter=${user.key}&baseURL=${baseUrl}"
Response.temporaryRedirect(URI.create(redirectUrl)).build()
}
I found my mistake, I needed to use call in the URL. Here is the code for the REST API:
import com.onresolve.scriptrunner.runner.rest.common.CustomEndpointDelegate
import groovy.json.JsonBuilder
import groovy.transform.BaseScript
import com.atlassian.jira.issue.Issue;
import javax.ws.rs.core.MultivaluedMap
import javax.ws.rs.core.Response
import org.apache.log4j.Logger
import groovy.transform.BaseScript
import com.onresolve.scriptrunner.runner.rest.common.CustomEndpointDelegate
import javax.ws.rs.core.MultivaluedMap
import com.atlassian.jira.component.ComponentAccessor
import com.onresolve.scriptrunner.runner.ScriptRunnerImpl
import com.atlassian.sal.api.ApplicationProperties
import com.atlassian.sal.api.UrlMode
import javax.ws.rs.core.Response
import com.atlassian.jira.component.ComponentAccessor
@BaseScript CustomEndpointDelegate delegate
def log = Logger.getLogger("atlassian-jira.log")
long iTracSuperFeatureSummaryUpdaterIssueTypeID= 10200;
int iTracSuperFeatureSummaryUpdaterProjectID= 23520;
String iTracSuperFeatureSummaryUpdaterURL= "http://itrac-service:8080/bulksummaryupdater/bulksplitter?key=:1:&reporter=:2:";
callMounaBulkSummary(httpMethod: "GET", groups: ["jira-administrators"]) { MultivaluedMap queryParams, String body ->
log.warn("MOUNA BULK")
def user = ComponentAccessor.jiraAuthenticationContext?.loggedInUser
Issue issue = ComponentAccessor.getIssueManager().getIssueObject(queryParams.getFirst("issueId") as Long)
def project = issue.getProject()
def baseUrl = ScriptRunnerImpl.getOsgiService(ApplicationProperties).getBaseUrl(UrlMode.ABSOLUTE)
log.warn("MOUNA BULK "+user+" "+issue+" "+baseUrl+" "+project +" "+project.get("id"))
iTracSuperFeatureSummaryUpdaterURL= iTracSuperFeatureSummaryUpdaterURL.replaceAll(":1:", issue.getKey())
iTracSuperFeatureSummaryUpdaterURL= iTracSuperFeatureSummaryUpdaterURL.replaceAll(":2:", user.getUsername())
def projectID=project.get("id")
int projectIDInt= projectID as int
if(iTracSuperFeatureSummaryUpdaterProjectID== projectIDInt && iTracSuperFeatureSummaryUpdaterIssueTypeID==Long.valueOf(issue.getIssueTypeId()) ){
Response.temporaryRedirect(URI.create(iTracSuperFeatureSummaryUpdaterURL)).build()
}
}
Other code for as similar REST endpoint:
import com.onresolve.scriptrunner.runner.rest.common.CustomEndpointDelegate
import groovy.json.JsonBuilder
import groovy.transform.BaseScript
import com.atlassian.jira.issue.Issue;
import javax.ws.rs.core.MultivaluedMap
import javax.ws.rs.core.Response
import org.apache.log4j.Logger
import groovy.transform.BaseScript
import com.onresolve.scriptrunner.runner.rest.common.CustomEndpointDelegate
import javax.ws.rs.core.MultivaluedMap
import com.atlassian.jira.component.ComponentAccessor
import com.onresolve.scriptrunner.runner.ScriptRunnerImpl
import com.atlassian.sal.api.ApplicationProperties
import com.atlassian.sal.api.UrlMode
import javax.ws.rs.core.Response
import com.atlassian.jira.component.ComponentAccessor
@BaseScript CustomEndpointDelegate delegate
def log = Logger.getLogger("atlassian-jira.log")
int iTracSuperFeatureSplitterIssueTypeID= 10200;
int iTracSuperFeatureSplitterProjectID= 23520;
String iTracSuperFeatureSplitterURL= "http://itrac-service:8080/featuregenerator/bulksplitter?key=:1:&reporter=:2:";
callMounaBulkSplitter(httpMethod: "GET", groups: ["jira-administrators"]) { MultivaluedMap queryParams, String body ->
log.warn("MOUNA BULK")
def user = ComponentAccessor.jiraAuthenticationContext?.loggedInUser
Issue issue = ComponentAccessor.getIssueManager().getIssueObject(queryParams.getFirst("issueId") as Long)
def project = issue.getProject()
def baseUrl = ScriptRunnerImpl.getOsgiService(ApplicationProperties).getBaseUrl(UrlMode.ABSOLUTE)
log.warn("MOUNA BULK "+user+" "+issue+" "+baseUrl+" "+project +" "+project.get("id"))
iTracSuperFeatureSplitterURL= iTracSuperFeatureSplitterURL.replaceAll(":1:", issue.getKey())
iTracSuperFeatureSplitterURL= iTracSuperFeatureSplitterURL.replaceAll(":2:", user.getUsername())
def projectID=project.get("id")
int projectIDInt= projectID as int
if(iTracSuperFeatureSplitterProjectID== projectIDInt && iTracSuperFeatureSplitterIssueTypeID==Long.valueOf(issue.getIssueTypeId()) ){
Response.temporaryRedirect(URI.create(iTracSuperFeatureSplitterURL)).build()
}
}