E9.2 Rest Connection Input Var available to Manipulate Body

DaveWagoner

DaveWagoner

VIP Member
Hi folks, hopefully some of you have run into something like this. I want to use an input var to the Connection Request in the Groovy Script area of "Manipulate Body". In this case I have a connection request iterating over an array of "project_id". I want to add that variable to the output json using Manipulate Body, but haven't figured out how to get the input var into the output groovy. Anyone run into this? The usual ${project_id} fails as you might imagine.

Since this is within an iterate loop I assume that using a orch-level variable wouldn't work too well.
1693242903271.png
 
I have a plan forward if this doesn't pan out, but it's not very pretty. Tossing this conn into its own orch, iterating the orch, and then having a script step after this to handle the array modification like I'm trying to do here.
 
@DaveWagoner, can you post an example of the response you are getting from api, as well as a mockup of the JSON output you want? The Manipulate Output section is the right spot to do this. I just need to see what's coming in and what you want going out, to give you the right groovy script.
 
Sure, here's a simplified sample of the API return:
JSON:
[{
        "id": 123456,
        "date": "2023-07-05"
    }, {
        "id": 234567,
        "date": "2023-07-05"
    }, {
        "id": 345678,
        "date": "2023-07-06"
    }
]

And here's what I'm trying to get. I know the groovy works, if I map in "project_id":"project_id" it inserts "project_id" into every array element. I'm just trying to get the component input var that i'm using in the path of the API call to also show up as an available var in the groovy

JSON:
[{
        "id": 123456,
        "date": "2023-07-05",
        "project_id": "1234"
    }, {
        "id": 234567,
        "date": "2023-07-05",
        "project_id": "1234"
    }, {
        "id": 345678,
        "date": "2023-07-06",
        "project_id": "1234"
    }
]
 
Last edited:
Sure, here's a simplified sample of the API return:
JSON:
[{
        "id": 123456,
        "date": "2023-07-05"
    }, {
        "id": 234567,
        "date": "2023-07-05"
    }, {
        "id": 345678,
        "date": "2023-07-06"
    }
]

And here's what I'm trying to get. I know the groovy works, if I map in "project_id":"project_id" it inserts "project_id" into every array element. I'm just trying to get the component input var that i'm using in the path of the API call to also show up as an available var in the groovy

JSON:
[{
        "id": 123456,
        "date": "2023-07-05",
        "project_id": "1234"
    }, {
        "id": 234567,
        "date": "2023-07-05",
        "project_id": "1234"
    }, {
        "id": 345678,
        "date": "2023-07-06",
        "project_id": "1234"
    }
]
Got it. Yeah, that's not going to work. What I would do is write a custom service request to add the project_id. You should be able to do it in a step right after the connector. In the transformations for your connector make sure Return Raw Output is turned on. This will enable you to pass in the raw json output from the connector to a custom request. Next, create a custom request with an input that will take the output of your connector, and a second input for the project_id. What your custom request needs to do is:

1) Use JsonSlurper to parse the connector output into an array of objects you can manipulate.
2) Iterate through your array, and add the project_id to each object
3) Use JsonBuilder to convert it back to json

I attached a screen shot of the code. Let me know if you have any questions.
 

Attachments

  • 2023-08-28_19-09-08.png
    2023-08-28_19-09-08.png
    415.8 KB · Views: 15
I maybe misunderstanding I had an issue like this before where I wanted to see my inputs and use them as outputs and also check how many records came back and make a message stating how many and I think I solved it by making a groovy step inside and passed in the input variable into an output variable, you can see it then..I think?

From memory the jsonIn.ServiceRequestN.variablename is tricky as N appears to be the order the Orch components fire

Code:
import com.oracle.e1.common.OrchestrationAttributes;
import java.text.SimpleDateFormat;
HashMap<String, Object> main(OrchestrationAttributes orchAttr, HashMap inputMap)

{
  HashMap<String, Object> returnMap = new HashMap<String, Object>();
    returnMap.put('recordCount',inputMap.get("recordCount"))
  return returnMap;
}

Then make Input = Output with the same name

Now in my manipulate output groovy I can see it
//Check if Data Request found a matching suggestion
if(jsonIn.ServiceRequest2.recordCount!=null)
{
jsonIn.scsResult='200002'
jsonIn.scsInfo = 'WARNING: No matching data found in E1 screen P4617'
}

I also see it in my output like this
"ServiceRequest2": {
"recordCount": "0"
},

Maybe not what you want but, you can also see ALL the inputs in the messages section as a drop down. Maybe not what you want but its just odd we can see them there no questions asked :)

So I am following for a better way to solve this issue :)
 
Last edited:
Back
Top