Forum Discussion

doubtsreadyapi's avatar
doubtsreadyapi
Contributor
5 years ago

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

  • richie's avatar
    richie
    Community Hero
    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
    • doubtsreadyapi's avatar
      doubtsreadyapi
      Contributor
      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
      • richie's avatar
        richie
        Community Hero
        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