Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

REST endpoint working fine for in line script but failing when using script editor

Mouna Hammoudi
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.
November 9, 2022

I am using a REST endpoint in scriptrunner and here is the code that I am using. The code is working fine when using an in line script but fails when specifying the file in scriptrunner where the code lies as shown in the following picture: 

 

Capture.PNG

import com.onresolve.scriptrunner.runner.rest.common.CustomEndpointDelegate

import groovy.transform.BaseScript

import com.atlassian.jira.issue.Issue;

import javax.ws.rs.core.MultivaluedMap

import javax.ws.rs.core.Response

import com.atlassian.jira.component.ComponentAccessor

import org.apache.log4j.Logger

import com.atlassian.jira.project.Project

import CreateMultipleSubtasks.Configuration_CreateMultipleSubtasks

@BaseScript CustomEndpointDelegate delegate

callSubTaskCreator(httpMethod: "GET", groups: ["jira-users"]) {MultivaluedMap queryParams, String body ->

def log1 = Logger.getLogger("atlassian-jira.log")

log1.warn("MOUNA CAMELIA223");

Configuration_CreateMultipleSubtasks conf =new Configuration_CreateMultipleSubtasks()

def MultipleSubtasksHashMap= conf.getSubTaskCreatorHashMap()

String itracCreatemultiplesubtasksProjectCategoriesURL = MultipleSubtasksHashMap["itracCreatemultiplesubtasksProjectCategoriesURL"] as String;

// String itracCreatemultiplesubtasksProjectCategoriesURL= "http://itrac-sustservice.eur.ad.sag:5555/web/subtaskmgr/Login.jsp?iTrac=:1:&reporter=:2:"

log1.warn("MOUNA CAMELIA223 "+itracCreatemultiplesubtasksProjectCategoriesURL);

 def user = ComponentAccessor.jiraAuthenticationContext?.loggedInUser

  def issueId = queryParams.getFirst("issueId") as Long

  Issue myissue = ComponentAccessor.getIssueManager().getIssueObject(issueId)

  def issueKey = myissue.getKey()

  def itracCreatemultiplesubtasksProjectCategoriesURL2 = itracCreatemultiplesubtasksProjectCategoriesURL.replaceAll(":1:", issueKey)

  def itracCreatemultiplesubtasksProjectCategoriesURL3 = itracCreatemultiplesubtasksProjectCategoriesURL2.replaceAll(":2:", user.getUsername())

  log1.warn("The rest endpoint has been executed by the user " +user)

  Response.temporaryRedirect(URI.create(itracCreatemultiplesubtasksProjectCategoriesURL3)).build()

 

}

This is what I get when I move the code into a file in the script editor. I am normally supposed to click on a button and move to a new page and this is what I get instead:

Capture1.PNG
Anyone knows what needs to be changed and how this can be fixed?

1 answer

0 votes
Florian Bonniec
Community Champion
November 9, 2022

Hi @Mouna Hammoudi 

Does the user who run the jira service have access to the file ?

 

Regards

Mouna Hammoudi
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.
November 10, 2022

@Florian Bonniec yes the user has all the required accesses. The code works perfectly as an in line script for the same user and fails once specified as a file in the REST endpoint. 

Suggest an answer

Log in or Sign up to answer