I am able query the data that I want from an integration within a process model, but when I try to map the Json results to a CDT process variable, all of the fields are blank. The keys from the Json dictionary are identical to the names for each field in the CDT. How can I map the Json dictionary into the CDT process variable?
Alternatively, how can I create an expression rule to parse each field from the Json and map each of them to a text process variable?
the following expression returns all key, value pairs from the Json: a!fromJson(rule!<rule_name>().result.body)
However, the following returns a null value:
a!fromJson(rule!<rule_name>().result.body).keyname1
Discussion posts and replies are publicly visible
Seems this is occurring due to the way your data from the integration is structured. You might be getting a list of Dictionary as shown in this example.
What is the output when you cast it? Try this:
index(cast('type!yourCDT?list', a!fromJson(...result.body), "keyname1", "No Value")
It says "expected 2 parameters, but found 4 parameters" when including this portion of the expression: , "keyname1", "No Value")
When I use the following ER I get the following error:
index(cast('type!{urn:com:appian:types}apiResultsData'(), a!fromJson(rule!API_Results(null).result.body)))
Expression evaluation error at function 'cast' [line 4]: Could not cast from apiResultsData to Number (Integer). Details: CastInvalidCould not cast from apiResultsData to Number (Integer). Details: CastInvalid
I am not trying to cast to an integer, as there are only text fields in the Json response and in the CDT.
The following is the result from the API Call:
Raw response body:
body: "{"args":{"ID":"99887766","File_Name":"PT_1","Type":"PT","Prob":"0.77"},"headers":{"x-forwarded-proto":"https","x-forwarded-port":"443","host":"postman-echo.com","x-amzn-trace-id":"Root=1-5f19cd4a-e32e53040178811afc5c3291","user-agent":"Appian","accept-encoding":"gzip,deflate"},"url":""">postman-echo.com/get error: null (Null) connectedSystem: null (Connected System)
When I convert JSON to Appian value:
body Dictionary
remove the () after type!{urn:com:appian:types}apiResultsData'() and instead do this:
index(cast('type!{urn:com:appian:types}apiResultsData', a!fromJson(rule!API_Results(null).result.body)))
or if you think you are going to get multiple values then:
index(cast('type!{urn:com:appian:types}apiResultsData?list', a!fromJson(rule!API_Results(null).result.body)))
if I run the first query above, I get the following error:
Expression evaluation error at function 'index': Too few parameters for function; expected at least 2 parameters, but found 1 parameters.
if I run the second query above, the error is: Invalid type for type constructor: apiResultsData?list
index(cast('type!{urn:com:appian:types}apiResultsData', a!fromJson(rule!API_Results(null).result.body)), "No Data")
that query executes but returns a null value when I replace "No Data" with a dictionary key
My recommendation is to encapsulate the integration into an expression rule. There you can do all the data conversion, casting and testing. This is our way of doing integrations. Just put two applications into production which completely run on integrations for data persistence.
Yeah that's what I've been trying to do. It took no effort to create an ER that returns the entire Json response, but have spent many hours trying to parse out individual values of the response or map them to a CDT.
Based on the raw response posted above your body contains "headers". This doesn't seem right. Headers should not be inside the body - see the structure of https://docs.appian.com/suite/help/20.2/Integration_Object.html#result. Once you get the correct body contents with your data you should be able to index into your fields correctly.
Thanks! That was the issue. The dictionary I wanted was nested as the value for the key "args", so the following query returns what I wanted.
index(cast('type!{urn:com:appian:types}apiResultsData', a!fromJson(rule!API_Results(null).result.body).args))
Can I add a query parameter of args to the Integration to enter this into the CDT, or is it still best to use casting?