I have a session variable called varIP1 which has a value like below: (It's mime type is application/java)
{abc={FedId=abc, Id=01FcLA, type=User, Profile={Id=02EmQA, type=Profile, Name=Analyst}}}
I am interested in extracting the first Id (01FcLA) from above using a function as given below:
%dw 1.0
%output application/json
%var myLib = readUrl("classpath://dwlib/my-global-functions.wev", "application/dw")
---
{
"Id": (myLib.idLookup(sessionVars.varIP1 ,$.Id,"Id") default null)
}
The global function that I'm using are:
%function validateLookup(lookupArray, key) 'true' when (lookupArray != null and IsNull(key) == 'false' and lookupArray[key] != null) otherwise 'false'
%function idLookup(lookupArray,key,value) (lookupArray[key][0][value] default '') as :string when (validateLookup(lookupArray,key) == 'true') otherwise null
With the above code, "Id" is coming as null. Any modifications needed above?
Thanks.