cancel
Showing results for 
Search instead for 
Did you mean: 

How to get only one of two items returned

swright
New Contributor III

In a mapper snap, my current expression is:
$[‘env:Envelope’][‘env:Body’][‘ns0:uploadFileToUcmResponse’].result[‘$’]

I only want the second value “123109” returned as a string. How can I do this? Thanks!

image

10 REPLIES 10

swright
New Contributor III

Sorry. My attachment didn’t get through due to a .json extension. I’m sending it now after change the extension to .txt.

image001.png

Copy_output0.txt (3.56 KB)

You are dealing with 2 separate input documents. The Mapper gets these one-by-one, not both of them at once.

Assuming the Mapper’s input is coming from a Json Parser, you can deal with this by unchecking “Process array” in the Json Parser settings. Then the Mapper will receive a single document whose root is an array. Then your expression would look like this:

jsonPath($, "$[*]['env:Envelope']['env:Body']['ns0:uploadFileToUcmResponse'].result['$']")[1]

Another approach is to filter the Mapper’s input so that you’re only getting the second document. To do that, insert a Head snap with an offset of 1.

@swright Try attached pipeline. If you are absolutely sure proper values comes on element 0/1 position then use[0/1] it else can filter over -1 criteria. I have added both in mapper.
community_Array_2020_10_29.slp (6.7 KB)

swright
New Contributor III

These looked like great solutions, but although they work perfectly in your sample pipeline, I can’t get them to work in mine. Mine are the output of a SOAP Execute Snap. This is one of the errors I am getting:

image

Thanks,
Scott

It’s because there is no value comes for results field from soap request. Just check the null safe option in mapper and save then value will come as null , no more exceptions will get.

Thanks,
Supratim
(+91)923-263-3466

This e-mail and any files transmitted with it are for the sole use of the intended recipient(s) and may contain confidential and privileged information. If you are not the intended recipient(s), please reply to the sender and destroy all copies of the original message. Any unauthorized review, use, disclosure, dissemination, forwarding, printing or copying of this email, and/or any action taken in reliance on the contents of this e-mail is strictly prohibited and may be unlawful. Where permitted by applicable law, this e-mail and other e-mail communications sent to and from Cognizant e-mail addresses may be monitored.