Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Celebration

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,560,550
Community Members
 
Community Events
185
Community Groups

using filed value in HTTPBuilder in scriptrunner

hi all,

I am using HTTPBuilder in scriptrunner to post something. I want to use a filed value in it as following:

 

def ss=issue.get("Summary")

def http=new HTTPBuilder('http://IP:Port/httpservice?user=msd&password=123&message=${ss}')

 

but above command leads to following error:

Message:
java.net.URISyntaxException: Illegal character in query at index 165: http://IP:Port/httpservice?user=msd&password=123&message=${ss}
Stack:
java.net.URI$Parser.fail(URI.java:2848)
java.net.URI$Parser.checkChars(URI.java:3021)
java.net.URI$Parser.parseHierarchical(URI.java:3111)
java.net.URI$Parser.parse(URI.java:3053)
java.net.URI.<init>(URI.java:588)
groovyx.net.http.URIBuilder.convertToURI(URIBuilder.java:93)
groovyx.net.http.HTTPBuilder.setUri(HTTPBuilder.java:794)
groovyx.net.http.HTTPBuilder.<init>(HTTPBuilder.java:213)
sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
java.lang.reflect.Constructor.newInstance(Constructor.java:423)
org.codehaus.groovy.reflection.CachedConstructor.invoke(CachedConstructor.java:83)
org.codehaus.groovy.runtime.callsite.ConstructorSite$ConstructorSiteNoUnwrapNoCoerce.callConstructor(ConstructorSite.java:105)
org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallConstructor(CallSiteArray.java:60)
org.codehaus.groovy.runtime.callsite.AbstractCallSite.callConstructor(AbstractCallSite.java:235)
org.codehaus.groovy.runtime.callsite.AbstractCallSite.callConstructor(AbstractCallSite.java:247)
script1565154997357525974272.run(script1565154997357525974272.groovy:20)

  it is noted that, when i used a solid value instead of ${ss} , as test, it works correctlt; but, I want to used a field value instead. any advise will be so appreciated

1 answer

0 votes
Mark Markov
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.
Aug 07, 2019

Hello @sahere 

If you want use GStrings you must use double quotes instead of  single

def ss=issue.get("Summary")

def http=new HTTPBuilder("http://IP:Port/httpservice?user=msd&password=123&message=${ss}")

many thanks for your reply it works.

now i have another problem. i have a custom field named as "Down time" and i want to send message consists of this fields as following:

MutableIssue issue = issue as MutableIssue
def created =issue.created
def closed=issue.resolutionDate
def s1=issue.summary
def bvField = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Down time")
def s2 = (Date)issue.getCustomFieldValue(bvField)

def http = new HTTPBuilder("http://IP:Port/httpservice?user=msd&password=123&message=${s1}+${s2}")

http.request( groovyx.net.http.Method.POST) {
}

but it makes following error:

2019-08-10 09:05:05,202 ERROR [workflow.ScriptWorkflowFunction]: *************************************************************************************
2019-08-10 09:05:05,202 ERROR [workflow.ScriptWorkflowFunction]: Script function failed on issue: CHKVKSER-48, actionId: 21, file: <inline script>
java.net.URISyntaxException: Illegal character in query at index 174: http://IP:Port/httpservice?user=msd&password=123&message=test9+2019-08-10 04:21:00.0
	at groovyx.net.http.URIBuilder.convertToURI(URIBuilder.java:93)
	at groovyx.net.http.HTTPBuilder.setUri(HTTPBuilder.java:794)
	at groovyx.net.http.HTTPBuilder.<init>(HTTPBuilder.java:213)
	at Script572.run(Script572.groovy:25)

could you please advise me about this?

many thanks for your reply. it works. but still there is a problem. i have a custom filed named as "Down time" and i want to use its value in message as following:

MutableIssue issue = issue as MutableIssue
def created =issue.created
def closed=issue.resolutionDate
def s1=issue.summary
def bvField = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Down time")
def s2 = (Date)issue.getCustomFieldValue(bvField)

def http = new HTTPBuilder("http://IP:Port/httpservice?user=msd&password=123&message=${s1}+${s2}")
http.request( groovyx.net.http.Method.POST) {
}

 

but it makes following error:

2019-08-10 09:05:05,202 ERROR [workflow.ScriptWorkflowFunction]: ************************************************************************************* 2019-08-10 09:05:05,202 ERROR [workflow.ScriptWorkflowFunction]: Script function failed on issue: CHKVKSER-48, actionId: 21, file: <inline script> java.net.URISyntaxException: Illegal character in query at index 174: http://IP:Port/httpservice?user=msd&password=123&message=test9+2019-08-10 04:21:00.0 at groovyx.net.http.URIBuilder.convertToURI(URIBuilder.java:93) at groovyx.net.http.HTTPBuilder.setUri(HTTPBuilder.java:794) at groovyx.net.http.HTTPBuilder.<init>(HTTPBuilder.java:213) at Script572.run(Script572.groovy:25)

 

could you please advise me about this?

it seems above issue is due to whitespace in summary and down time field. how can i handle the whitespace issue? 

the input field has white space but in the message part whitespace leads to error

Add after defining the http fully the line: http = http .replaceAll("\\s","")

This removes the whitespace / carriage returns.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events