I am getting the below response from Integration which is of type HttpResponse
[statusLine=HTTP/1.1 200 OK, statusCode=200, headers=[object Object], contentType=application/json; charset=utf-8, body={"jobId":"01091664F27E4771A9B92AEA0CC577ED"}].
I need to get the JobId value from the above and i ll have to map it to a process variable. To achieve this, i used an expression rule and used the below code:
if(a!isNotNullOrEmpty(ri!integrationResponse),a!fromJson(index(ri!integrationResponse, "body", null)),{})
It resulted in "[jobId:01091664F27E4771A9B92AEA0CC577ED]" but i only need the JobId value from it. I tried various functions but nothing seems to be working.
Can someone please suggest on how to proceed with this?
Discussion posts and replies are publicly visible
You need to step through this piece by piece to understand what's actually going on.
Firstly we can see that the "body" you're getting back is a JSON string (I can see you're already trying to treat it as JSON but just reiterating here for clarity).
So when "body" is populated, we will want to translate it back from JSON, which of course results in a dictionary:
Now of course, as with all dictionaries/CDTs/maps, if we want only the property within the dictionary, we actually have to retrieve the value of that property (Even when the entire dictionary only holds one property). For this, dot property would work, but if there's ever a chance it would be empty, it would be safer to use property(). (Note as always: property() and index() are the same function in the back-end; but my personal best practice is to use property() for properties, and index() for indices [i.e. positional within an array], for code cleanliness and readability).
Side note: if you're passing the "body" value directly into a!fromJson(), then your null-safe returned value should be something that doesn't cause a!fromJson() to crash - I've found "[]" or "{}" work well. It will error on you if you pass it null().
Good explanation.