Forums

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

Wierd error in script runner script to return value

serge calderara
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.
April 30, 2020

Dear all, 

I have trying to use script runner to return an object value from a method called defined as below :

==> start script

import groovy.json.*
import groovyx.net.*
import groovyx.net.http.*
import static groovy.json.JsonOutput.*
import static groovyx.net.http.ContentType.*
import static groovyx.net.http.Method.*
import groovy.json.JsonSlurper

def AZAD_tenant_ID="xxxxxxxxxxx"
String targetUrl = 'https://login.microsoftonline.com/' + AZAD_tenant_ID +'/oauth2/token'
def http = new HTTPBuilder(targetUrl)

class ResultToken {
String token
String expiration
}

ResultToken getToken(){
ResultToken token

http.request(POST) {

requestContentType = URLENC

body = [

.....
]

response.success = { resp, json ->
token = new ResultToken(token: json["access_token"].toString(), expiration: json["expires_in"].toString())

}
}
}

//calling method to get token
def myToken=new ResultToken()
mytoken=getToken()
return mytoken.token

 

When I try to run my script in script runner console I have an exception error as below :

"groovy.lang.MissingPropertyException: No such property: http for class: Script359 at Script359.getToken(Script359.groovy:21) at Script359.run(Script359.groovy:41)"

Any idea how to solved ?

1 answer

0 votes
Nic Brough -Adaptavist-
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.
May 3, 2020

The object http in your script is of a type that doesn't have a getToken method.  You'll need to look through the docs for the class to work out what it should be doing.

Suggest an answer

Log in or Sign up to answer