Null Value Support

Null data values are represented in MessageValue objects, belonging to a MessageValue collection that is created from the data message sent by the server.

Note: Null data values are not supported on the Windows Mobile platform.

This document refers to example HTML. You can see the example HTML by downloading the hybridapp_null_value.zip file and extracting the hybridapp_null_value.html file.

In the example, MessageValueCollection is referenced by var values = myDataMessage.getValues();” and myDataMessage is created in the onHybridAppLoad method.

A specific MessageValue is referenced by values.getData(string key). If you use the Hybrid App designer, the IDE manages keys for you but with JavaScript API, you have to implement key management in the code yourself.

This example follows the IDE style of giving each control an ID  and using that as the key for data that will be used in that control:
<input class="right" type="number" id="Nullvaluetest_int_value2_attribKey" 
smp_allows_null="true" smp_valuechanged="false" onchange="inputChanged(this)"/>

So if you want the MessageValue object corresponding to that control:

var value = values.getData(“Nullvaluetest_int_value2_attribKey”); 
Once you have the MessageValue object you can see if it is null with:
var isNull = value.getNullAttribute(); 

Null Values and HTML

HTML usually puts an empty string into a control if it is assigned a null value. If the control is not changed but you get the data from it for its MessageValue object, the MessageValue object will have an empty string as its value instead of NULL. This means the NullAttribute is not set properly unless you set it yourself.

When using null values, keep in mind that the contents of the control do not tell you whether it should be null. This can cause bad data on the server. Putting an empty string into a number type MessageValue can throw a formatting exception on the server, so when using JavaScript API, you are responsible for maintaining null values.

The Sample HTML

This section references the hybridapp_null_value.html file to show examples of how to implement null values.