Forum Discussion
You can try something like what I've posted below. If it doesn't work, can you provide your response for the two calls so I can navigate the response with groovy and parse it out better? Even if it's a sample mocked up response.
def aaa = context.expand( '${1st Call#Response#$[\'data\'][\'res\'][\'b\'][0][\'aaa\']}' ) def response = context.expand( '${2nd call#Response#$[\'data\'][\'res\'][\'reportDownloadUrls\'][\'$aaa\']}' )
Typically when working with strings, you can use $ and a variable name to make the string's contents respect it as a variable. So the two are the same below:
log.info ("Hello world, my name is Matthew."); def name = "Matthew"; log.info("Hello world, my name is $name.");
Looking at this, it's not as simple as I thought it was. Still, to be a better help, can you provide sample or mocked up response that I can parse with groovy? That would help me a log, as I am unfamiliar with the syntax you are using in the content.expand statement.
- subhaD5 years agoContributor
the reportdownloadUrls[99999999] is the value am trying to extract.
but 99999999 is from 1st request response am trying to take it in variable and pass it to this value, but not sure how to pass it ??
def URL = context.expand( '${2nd call#Response#$[\'data\'][\'resource\'][\'reportDownloadUrls\'][\'999999999\']}' )
I wanna parametrize the 999999999 part
- groovyguy5 years agoChampion Level 1
I understand that part, and I am tyring to help here as best I can with the limited information I have so far. The groovy script is doing a content expand with some sort of pathing that I am not familiar with, which makes this a lot more difficult for me to try to help.
If you could provide a mocked up response that you're actually trying to parse to run the groovy script against to troubleshoot as I go? That would be beyond helpful.
That being said, and while it may not be pretty, this MIGHT work for you. I cannot test it, since I don't have the response to parse and try:
def aaa = context.expand( '${1st Call#Response#$[\'data\'][\'res\'][\'b\'][0][\'aaa\']}' ) // This sets up the content expansion string to be a literal string, and add in the parameterized aaa variable. def respString = '''${2nd call#Response#$[\'data\'][\'res\'][\'reportDownloadUrls\'][\'''' + aaa + '''\']}\'''' def response = context.expand( respString )
Related Content
- 20 days agoStoplight
- 2 years agopstachelek
Recent Discussions
- 35 minutes agoisbiat
- 47 minutes agodipsthorat
- 24 hours agoarmygrad