-
Notifications
You must be signed in to change notification settings - Fork 1
Setting Entry Values
Entries have methods to set the value.
When you put an entry value:
- if the entry didn't exist, a new entry is created and the value assigned
- if the entry already exists, the previous value is replaced
There are two methods:
-
put
: puts the provided value as is -
putConverted
: converts the provided value and puts the converted value
Similarly, to get an entry, you first invoke an entry method and then invoke a put* method.
The following example sets an Integer value of 900 to the releaseYear entry:
document.entry("releaseYear").put(2016);
If you prefer compile safety to ensure the type you provide is indeed the one you intended, you may use one of the *Entry
methods with the specific type to store. The following example uses intEntry
to ensure an Integer value is provided:
Integer releaseYear = 2016;
// possibly more code in between
document.intEntry("releaseYear").put(releaseYear);
This will prevent accidentally using another type, such as Float when releaseYear was assigned.
The putConverted
method is used to automatically convert a value to the desired type, especially as String, which is very common in webMethods documents.
The following example stores releaseYear as a String. Note that the conversion from Integer to String is performed automatically.
Integer releaseYear = 2016;
// possibly more code in between
document.stringEntry("releaseYear").putConverted(releaseYear);
The only caveat with putConverted
is that it's not compile-safe. If you pass a value that can't be converted, an exception is thrown at run time.