Data Type Conversion
To discuss or ask questions about this article, select the discussion tab above.
Overview
This This article details how to convert from one data type to another in Spel code. This concept is regarded as casting.
Details
Primary data types used in USD spell.
- string
- int
- float
- date
- duration
- bool
- uuid (introduced in r11.x)
- object
Example: <source lang="javascript">string MyString; int MyInt; float MyFloat; date MyDate; duration MyDuration; uuid MyUUID;
MyString = "Hello world no: " +(string) 1; // result: "Hello world no: 1" MyInt = (int) "2 times"); // result: 2 MyFloat = (float)MyInt; // result: 2.00000 MyDate = (date)( (string) now()); // result: the actual date depending of your system time configuration MyDuration = (duration)((int) "2" + 3), // result: duration of 5 sec. MyUUID = (uuid)expand( "&{'mylogin'=cnt.userid->id}"); // result: the id of contact having userid "mylogin"</source>
Arrays
In Spell code you can use arrays as well.
Accessing array fields is very similar to other languages, simply use <source lang="javascript"> myArray[3] </source> to access forth element of an array myArray. Arrays are 0-based.
Here is the example of declarantion of a new array of strings with 4 elements: <source lang="javascript">string msgs[4];</source>