cancel
Showing results for 
Search instead for 
Did you mean: 

Require Groovy script for Parameterizing the value in next request

SOLVED
Highlighted
Contributor

Require Groovy script for Parameterizing the value in next request

Hi

 

My GET Method response is like below, But when i do get once the Id changes and the place "journals|0_0_7|JOURNALS_PART_ONE" and "journals|0_0_7|JOURNALS_MAPPING" changes, that is some times "journals|0_0_7|JOURNALS_MAPPING" comes 2nd in the response and some times it will come last.

 

So i require a groovy script depending upon the Pack id i must get the "id" and parameterize that "id" to the next request. 

 

"dependencies" : [
{
"id" : 13311,
"pack_id" : "journals|0_0_7|PART_TWO",
"status" : "not_started",
"output" : null,
"run_id" : null
},
{
"id" : 13312,
"pack_id" : "journals|0_0_7|PART_ONE",
"status" : "complete",
"output" : null,
"run_id" : ""
},
{
"id" : 13313,
"pack_id" : "journals|0_0_7|MAPPING",
"status" : "waiting",
"output" : [
{
],

 

Hope the question is clear and please help in groovy script.

 

Thanks

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
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

18 REPLIES 18
Highlighted
Community Hero

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

Hey @doubtsreadyapi,

Could you rephrase the following? I really couldnt follow it

"My GET Method response is like below, But when i do get once the Id changes and the place "journals|0_0_7|JOURNALS_PART_ONE" and "journals|0_0_7|JOURNALS_MAPPING" changes, that is some times "journals|0_0_7|JOURNALS_MAPPING" comes 2nd in the response and some times it will come last."

Later on in your post you mention passing the id attribute value to a subsequent request. You can do this with the embedded property transfer functionality in several ways without having to rely on groovyscript very easily.....although the bit you mention that i didnt understand might preclude you using the property xfer functionality.

Can you please explain the bit i got lost with?

Also...your GET request....does your GET include a filter (REST query parameter perhaps)....maybe the id attribute?

Cheers

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
Highlighted
Contributor

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

Hi

In GET response, the json node for journals|0_0_7|JOURNALS_PART_ONE and journals|0_0_7|JOURNALS_Mapping will get change its not static, ie some times journals|0_0_7|JOURNALS_PART_ONE will come in first or 2nd or third node in the response.. so in response where ever the journals|0_0_7|JOURNALS_PART_ONE is available i want to get the id for this and pass it to the next request... hope this helps..

You have mentioned.. using property transfer we can do it.. but the node value of the parameter changes.. still it can be acheived through property transfer?

Please let me still if any info is requied
Highlighted
Community Hero

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

Hey @doubtsreadyapi,

Ok. The groovy you want is pretty straightforward so i even i can do it, but it'll take me a couple of hours cos my groovy's rubbish! (i'll start putting it together later tonight), so i suspect either @nmrao or @HimanshuTayal will beat me to it, but i should have some working code for you tomorrow if they dont check the forum today.

As to using the embedded property transfer functionality in this case id grab the id value and write it to a property in a Properties step (via my groovyscript) which will then allow you to use the embedded property expansion functionality to reuse in a subsequent step.

Cheers,

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
Highlighted
Community Hero

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

There isn't any such string "journals|0_0_7|JOURNALS_PART_ONE" in the json that you provided


Regards,
Rao.
Highlighted
Community Hero

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

@nmrao,

I think thats a typo fella.

I think @doubtsreadyapi meant "journals|0_0_7|PART_ONE"

The response payload is as follows:

"dependencies" : [
{
"id" : 13311,
"pack_id" : "journals|0_0_7|PART_TWO",
"status" : "not_started",
"output" : null,
"run_id" : null
},
{
"id" : 13312,
"pack_id" : "journals|0_0_7|PART_ONE",
"status" : "complete",
"output" : null,
"run_id" : ""
},
{
"id" : 13313,
"pack_id" : "journals|0_0_7|MAPPING",
"status" : "waiting",
"output" : [
{
],

I believe @doubtsreadyapi wants to grab the id attribute value (for later use stored as property) that is associated to the record that has "pack_id" = "journals|0_0_7|PART_ONE"

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
Highlighted
Community Hero

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

Hey @doubtsreadyapi,

Check out the following link....it does what you need in xml....change the xml to json and you should be spiffy.

All credit for answer goes to @nmrao as he provided the answer in link

https://community.smartbear.com/t5/SoapUI-Pro/Property-Transfer-Conditional/td-p/199581/page/2

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
Highlighted
Contributor

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

Hi

I havent find any groovy script related to my requirement. Yes it was typo in the response it contains the same parameters what i mentioned in description.as rao mentioned depending upon the text i have to capture the id and paramterize in next request.

Thanks
Highlighted
Community Hero

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

Ok. Thank you for confirmation.

Do you need to grab id when status is complete and this value is always fixed?


Regards,
Rao.
Highlighted
Contributor

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

Hi @nmrao 

 

The Pack_id :""pack_id" : "journals|0_0_7|PART_ONE", remains fixed, where as for this pack_id i have to pick the id and parameterize to next request,  But the node value for pack_id keep changing i said eariler the pack_id : journals|0_0_7|PART_ONE, will be coming last in the response ,  The id value will keep changing. Status doesnt matter.

 

So in the below response, if ""pack_id" = "journals|0_0_7|PART_ONE", i have to pick the id for this pack_id and parameterize to the next request.

 

"dependencies" : [
{
"id" : 13311,
"pack_id" : "journals|0_0_7|PART_TWO",
"status" : "not_started",
"output" : null,
"run_id" : null
},
{
"id" : 13312,
"pack_id" : "journals|0_0_7|PART_ONE",
"status" : "complete",
"output" : null,
"run_id" : ""
},
{
"id" : 13313,
"pack_id" : "journals|0_0_7|MAPPING",
"status" : "waiting",
"output" : [
{
],

 

Thanks

New Here?
Join us and watch the welcome video:
Announcements
Top Kudoed Authors