Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

How to check if apigee flow variable is empty or null in javascript

Not applicable

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 Solved
1 6 8,809
1 ACCEPTED SOLUTION

Not applicable

@Sujnana Rai try this please.

function isEmpty(data) {

if (data) {

return true;

}

return false;

}

View solution in original post

6 REPLIES 6