cancel
Showing results for 
Search instead for 
Did you mean: 

Require Groovy script for Parameterizing the value in next request

SOLVED
Community Hero

Re: Require Groovy script for Parameterizing the value in next request

Thanks.
However, it appears that you have picked up part of the response from middle of a response.
Using below similar type of solution,  you should be able to work it out for the original response.

https://github.com/nmrao/soapUIGroovyScripts/blob/master/groovy/json/QueryRelativeData.groovy

Need complete hierarchy of the response, it is fine even if it is sample one if you still have issues.



Regards,
Rao.

View solution in original post

Contributor

Re: Require Groovy script for Parameterizing the value in next request

Hi @nmrao 

 

I have tried with the below code, where as i am getting null pointer exception, attached is the error for the same.

 

My code is

import groovy.json.JsonSlurper;

def res = context.expand( '${Get_Period_Id#Response}' )

def packid = new groovy.json.JsonSlurper().parseText(res).result.find{it.pack_id =="journals|0_0_7|JOURNALS_PART_ONE"}.dependencies

 

 

My response node is like below, i have to dependency_parameters instead of dependencies?

 

"dependency_parameters" : {
"c_fa" : [
{
"journals_in_scope" : true,
"company_codes" : [
"1",
"16",

],
"id" : "s7879987998",
"name" : "abcd"
}
]
},

"dependencies" : [
{
"id" : 13336,
"pack_id" : "journals|0_0_7|JOURNALS_PART_TWO",
"status" : "not_started",
"output" : null,
"run_id" : null
},
{
"id" : 13337,
"pack_id" : "journals|0_0_7|JOURNALS_PART_ONE",
"status" : "not_started",
"output" : null,
"run_id" : null
},
{
"id" : 13338,
"pack_id" : "journals|0_0_7|JOURNALS_MAPPING",
"status" : "not_started",
"output" : null,
"run_id" : null
}
]
}

 

 

Community Hero

Re: Require Groovy script for Parameterizing the value in next request

Is it a valid json which you posted latest?


Regards,
Rao.
Contributor

Re: Require Groovy script for Parameterizing the value in next request

@nmrao 

 

Yes its valid json, but this got resolved i tried in different way, it worked

 

Thanks for the help

Community Hero

Re: Require Groovy script for Parameterizing the value in next request

Glad you got it working.


Regards,
Rao.
Community Hero

Re: Require Groovy script for Parameterizing the value in next request

Hey @doubtsreadyapi!

I got a script working but its different to yours and far less efficient. Im learning so would welcome if you posted the working script you used?

You published the script you were using but it was erroring out and you made some sort or change, so would you mind in the interests of my education, publish the working script?

Many thanks fella,

Rich
if this helped answer the post, could you please mark it as 'solved'? Also if you consider whether the title of your post is relevant? Perhaps if the post is solved, it might make sense to update the Subject header field of the post to something more descriptive? This will help people when searching for problems. Ta
Contributor

Re: Require Groovy script for Parameterizing the value in next request

Hey @richie 

 

Attached is the script which worked for me as per my requirement.

 

Thanks

Community Hero

Re: Require Groovy script for Parameterizing the value in next request

Hey @doubtsreadyapi,

Thanks man.....youre the best!

Rich
if this helped answer the post, could you please mark it as 'solved'? Also if you consider whether the title of your post is relevant? Perhaps if the post is solved, it might make sense to update the Subject header field of the post to something more descriptive? This will help people when searching for problems. Ta
Community Hero

Re: Require Groovy script for Parameterizing the value in next request

Hey @doubtsreadyapi!

Im not picking holes in your script but reading it, im wondering if the script actually does what you asked for.

Originally i thought your response could return multiple records (at least 3) and you wanted to extract the "id" attribute value where "pack_id" = "journals|0_0_7|JOURNALS_PART_ONE" and this particular record could appear in your response at any position (so it could be generated in record1, or record2, or record3......recordx) was that correct?

The reason i ask is that currently the script will write out the "id" value to a testcase level property if "pack_id" = "journals|0_0_7|JOURNALS_PART_ONE" if it is generated in record1 and if it isnt, then the else part executes and it writes the "id" value to the testcase level property whatever the "pack_id" value is.

I dont think this script does what you originally asked for cos it assumes that there isnt more than 2 records in the response and the else will write the "id" value to the property when the "pack_id" isnt "journals|0_0_7|JOURNALS_PART_ONE"

Please understand.....im not criticising at all, i just wanna make sure your script does exactly what you need as it doesnt appear to equate to your initial requirements considering the response payload appears to include the record youre actually interested in, anywhere in your response and the response contains multiple (at least 3) records.

Nice one,

Rich
if this helped answer the post, could you please mark it as 'solved'? Also if you consider whether the title of your post is relevant? Perhaps if the post is solved, it might make sense to update the Subject header field of the post to something more descriptive? This will help people when searching for problems. Ta
New Here?
Join us and watch the welcome video:
Announcements
Top Kudoed Authors