Patrick Kelly
Posts: 0
Joined: Wed Nov 20, 2013 6:00 am

How do you use an if statement to verify "undefined" value returned by REST service?

I have uploaded a .csv full of contact information for various partner businesses in my app. I am using a REST service to send the ID and populate each business' page by entering the string values of each cell into corresponding labels. This is working great. However, not all businesses have all the information. For example, some are missing a website. As a result, I get something like:

Name: Business Name
Phone: (123) 456-7890
Email: a href="mailto:example@email.com" rel="nofollow"example@email.com/a
Website: undefined

I would like to use an if statement to make the field go invisible if the result is undefined. This is what I initially tried:

if(Appery(“bizWeb").text == "undefined"){
Apperyio('bizWeb').hide();
} else {}

If the label text reads "undefined" (which it does), then it should hide the label. However, despite the fact that the label displays "undefined", when I use an alert to show what Appery.(bizWeb).text actually contains, it shows me this function:

"function ( value ) {
var hooks, ret, isFunction,
elem = this[0];

if ( !arguments.length ) {
if ( elem ) {
hooks = jQuery.valHooks[ elem.type ] || jQuery.valHooks[ elem.nodeName.toLowerCase() ];

Code: Select all

 if ( hooks && "get" in hooks && (ret = hooks.get( elem, "value" )) !== undefined ) { 
  return ret; 
 } 

 ret = elem.value; 

 return typeof ret === "string" ? 
  // handle most common string cases 
  ret.replace(rreturn, "") : 
  // handle cases where value is null/undef or number 
  ret == null ? "" : ret; 
} 

return; 

}

isFunction = jQuery.isFunction( value );

return this.each(function( i ) {
var val,
self = jQuery(this);

Code: Select all

if ( this.nodeType !== 1 ) { 
 return; 
} 

if ( isFunction ) { 
 val = value.call( this, i, self.val() ); 
} else { 
 val = value; 
} 

// Treat null/undefined as ""; convert numbers to string 
if ( val == null ) { 
 val = ""; 
} else if ( typeof val === "number" ) { 
 val += ""; 
} else if ( jQuery.isArray( val ) ) { 
 val = jQuery.map(val, function ( value ) { 
  return value == null ? "" : value + ""; 
 }); 
} 

hooks = jQuery.valHooks[ this.type ] || jQuery.valHooks[ this.nodeName.toLowerCase() ]; 

// If set returns undefined, fall back to normal setting 
if ( !hooks || !("set" in hooks) || hooks.set( this, val, "value" ) === undefined ) { 
 this.value = val; 
} 

});
}"

not "undefined". Any ideas? I'm sure that I'm just going about this all wrong.

M&M
Posts: 0
Joined: Tue Nov 11, 2014 6:59 am

How do you use an if statement to verify "undefined" value returned by REST service?

In your response mapping, each of the field mapping comes with a JS code editor - specific to that field mapping. It calls a function with the returned value as a parameter. Here you can read the value...and do some processing and either return same value, or a new value. The code will be easier to read / maintain that way

Return to “Issues”