I'm trying the following imports in a Profields custom script field.
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.config.properties.APKeys
import com.onresolve.jira.groovy.user.FieldBehaviours
import groovy.transform.BaseScript
import groovyx.net.http.RESTClient
import org.apache.http.HttpRequest
import org.apache.http.HttpRequestInterceptor
import groovyx.net.http.HttpResponseException
import org.apache.http.HttpResponse
import org.apache.http.protocol.HttpContext
import groovyx.net.http.ContentType.JSON
import groovyx.net.http.Method.GET
import groovyx.net.http.Method.PUT
This works in ScriptRunner but in Profields/Project Navigator it generates the following errors.
[c.d.j.p.i.value.service.GroovyValueService] Error while getting the Script field value: startup failed:
Script1.groovy: 5: unable to resolve class groovyx.net.http.RESTClient
@ line 5, column 1.
import groovyx.net.http.RESTClient
Script1.groovy: 8: unable to resolve class groovyx.net.http.HttpResponseException
@ line 8, column 1.
import groovyx.net.http.HttpResponseException
Script1.groovy: 11: unable to resolve class groovyx.net.http.ContentType.JSON
@ line 11, column 1.
import groovyx.net.http.ContentType.JSON
Script1.groovy: 13: unable to resolve class groovyx.net.http.Method.PUT
@ line 13, column 1.
import groovyx.net.http.Method.PUT
Script1.groovy: 12: unable to resolve class groovyx.net.http.Method.GET
@ line 12, column 1.
import groovyx.net.http.Method.GET
Script1.groovy: 3: unable to resolve class com.onresolve.jira.groovy.user.FieldBehaviours
@ line 3, column 1.
import com.onresolve.jira.groovy.user.FieldBehaviours
6 errors
I probably don't need the com.onresolve one but definitely need RESTClient as I'm making a post request to Tempo timesheets to populate a custom field. Anyone know how to accomplish this?
Hi @RJA ,
I'm Fede Baronti from DEISER's Customer Support (Profields' developers). We are really glad that you are using Profields and raising your concerns.
Unfortunately, you will not be able to use those imports with Profields as it won't recognize them (hence all this list of errors you shared).
Here you will find an example of a script that will allow you to fetch information from REST endpoints and show the results in Profields script fields:
/* REST CALL THROUGH JAVA */ import com.google.gson.JsonParser import org.json.JSONObject import javax.xml.bind.JAXBContext import java.nio.charset.StandardCharsets String url = "http://YOURURL/rest/profields/api/2.0/fields?expand=sorting";String auth = "admin" + ":" + "a"; byte[] encodedAuth = Base64.getEncoder().encode(auth.getBytes(StandardCharsets.UTF_8)); URL url = new URL(url); HttpURLConnection connection = (HttpURLConnection) url.openConnection(); connection.setRequestMethod("GET"); connection.setRequestProperty("Accept", "application/json"); connection.setRequestProperty("Authorization", "Basic " + new String(encodedAuth)) InputStream result = connection.getInputStream() JsonParser jsonParser = new JsonParser() String resultStr = jsonParser.parse( new InputStreamReader(result, "UTF-8")) connection.disconnect(); return resultStr
Please, let us know if this answer helped you. Also, keep in mind that we have a Service Desk portal to assist you with this or any other concerns: https://marketplace.atlassian.com/apps/1210816/profields-jira-project-tracking?hosting=server&tab=support
Thanks and all the best,
Fede.
Thanks Fede!
The pure java code actually works. It seems to be a little slower than the groovy code I was using but that's another topic.
FYI for anyone else interested, I also had to send the following headers to Tempo's API to get a response.
connection.setRequestProperty("X-Atlassian-Token", "no-check")
connection.setRequestProperty("Content-Type", "application/json")
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
while importing package I am also getting simillar issue
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed: /home/cg/root/7599157/main.groovy: 19: unable to resolve class groovyx.net.http.ContentType @ line 19, column 1. import groovyx.net.http.ContentType ^ /home/cg/root/7599157/main.groovy: 17: unable to resolve class groovyx.net.http.HTTPBuilder @ line 17, column 1. import groovyx.net.http.HTTPBuilder ^ /home/cg/root/7599157/main.groovy: 18: unable to resolve class groovyx.net.http.ContentType @ line 18, column 1. import static groovyx.net.http.ContentType.* ^ /home/cg/root/7599157/main.groovy: 20: unable to resolve class groovyx.net.http.Method @ line 20, column 1. import static groovyx.net.http.Method.* ^ /home/cg/root/7599157/main.groovy: 18: unable to resolve class groovyx.net.http.ContentType @ line 18, column 1. import static groovyx.net.http.ContentType.* ^ /home/cg/root/7599157/main.groovy: 20: unable to resolve class groovyx.net.http.Method @ line 20, column 1. import static groovyx.net.http.Method.* ^ 6 errors
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.