How to check if apigee flow variable is empty or null in javascript? For example, here I am creating flow variable called screeningReturn from xml payload.
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <ExtractVariables async="false" continueOnError="false" enabled="true" name="EVExtractScreeningResults"> <DisplayName>EV.ExtractScreeningResults</DisplayName> <IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables> <Source clearPayload="false">screeningReturnResponse</Source> <XMLPayload stopPayloadProcessing="false"> <Namespaces/> <Variable name="screeningReturn" type="nodeset"> <XPath>/Results</XPath> </Variable> </XMLPayload> </ExtractVariables>
The variable screeningReturn can be null if xml has don't have Results tag. I need to check this in java script. I am using below function to do null or empty check.
function isEmpty (data) { if(typeof(data) == 'number' || typeof(data) == 'boolean') { return false; } if(typeof(data) == 'undefined' || data === null ) { return true; } if(typeof(data.length) != 'undefined') { return data.length == 0; } for (var h in data) { if (data.hasOwnProperty(h)) { return false; } } return true; };
But I am getting following error - TypeError: Cannot find function hasOwnProperty in object com.apigee.flow.Variables@44a8ce54.
Solved! Go to Solution.
User | Count |
---|---|
1 | |
1 | |
1 | |
1 | |
1 |