There are often times when a developer may need to work with an object, or an entity. This object, or entity, can contain many different types of data and those specific types may need to be handled differently. For example, a picture may get lost when converted to a text if not handled correctly.
Within the specified object, or entity, there may include a data type that the developer may wish to verify.
One use case of this Utility Method would be to check if an object contains a picture.
NOTE: We can check any type by passing the constant as a parameter ($2).
To check if this type exist within the object, we can use the utility method below.
$1 - Object or Entity
$2 - Constant of the Field and Variable Types theme (shown below)
The Value Type command returns the type of the value resulting from the evaluation of the expression you passed as a parameter.
The command returns a numeric value that can be compared with one of the following constants of the Field and Variable Types theme:
Here are the steps to the utility method and the code is provided below.
| // Utility Method - Util_ObjContains |
#DECLARE($obj : Object; $type : Integer)->$result : Boolean
var $att : Text
If (Count parameters=2)
For each ($att; $obj) Until ($result)
If ((Value type($obj[$att]))=$type)
End for each
|$hasPictureValue:=Util_ObjContains($test_o; Is picture) |
$hasRealValue:=Util_ObjContains($test2_o; Is real)