Parameter variables
These are the values passed to the UDR in the list of parameters. Because SIL™ uses a "pass-by-value" policy, even though you modify the value of these variables in the body of the function, on exit, their original values will be restored.
Insert excerpt |
---|
| User-defined Routines (UDR) |
---|
| User-defined Routines (UDR) |
---|
nopanel | true |
---|
|
Global variables
These are the variables that are already defined and can be used right away (issue fields, customfields and any variables defined before the routine). You can use issue fields and custom fields anywhere in your code (including in the UDR body) without having to declare them.
Code Block |
---|
function printKey(){
print(key);
} |
Notice that the key variable is a standard issue field that you could otherwise use anywhere in your SIL™ program without having to declare it.
Return value
Return values can be used to communicate with the context that called the UDR or to halt its execution.
Examples
Code Block |
---|
function isEven(number a){
return (a % 2 == 0);
} |
Code Block |
---|
function increment(number a){
return a + 1;
}
number b = increment(2); |
Notice that there is no need to declare the type of the return value; this will be evaluated at runtime. Therefore, even though the check on the following program will be ok, at runtime the value of d will NOT be modified because of the incompatibility between date (on the right-hand-side) and number (on the left-hand-side).
Code Block |
---|
function increment(number a){
return a + 1;
}
date d = increment(2); |
Note |
---|
There can be only one return value (at most). If you would like to return more values of the same type, consider using an array or a struct. |
You can return simply from a routine without specifying a value. However, you should always remember that by design routines return a value, even if it is undefined. The following code is therefore valid:
Code Block |
---|
function f(number a) {
if(a > 0) {
print("positive");
return;
}
if(a == 0) { print("ZERO"); }
}
//[...................]
string s =f(4); //s is still undefined, no value was returned
if(isNull(s)) {
print("S IS NULL!"); //this will be printed
} else {
print("S IS NOT NULL!");
}
|
Of course, the above code will print the text 'S IS NULL' in the log.