@Return (JavaScript)

Returns execution to the calling function or the user interface.

Defined in

@Functions (JavaScript)

Syntax

@Return(value:any) : void
Parameter Description
value The return value. If the parameter is null or omitted, the return value is an empty string.

Usage

@Return returns to the calling function when used in a called function.

@Return returns to the user interface when used in a top-level function.

Typically @Return is superfluous. A function automatically returns following its last statement. If the last statement of a function is a value, that value is returned. However, using @Return or the return statement is good form.

Examples

(1) This example is the formula for a computed field. It returns a value based on a condition.
var n = @GetNumberField("//field3");
@If(
	n > 0, @Return("Positive number"),
	// else if
	n < 0, @Return("Negative number"),
	// else
	@Return("Zero")
);

(2) This example is equivalent to the first. In most cases, an @Return statement is not necessary.

var n = @GetNumberField("//field3");
@If(
	n > 0, "Positive number",
	// else if
	n < 0, "Negative number",
	// else
	"Zero"
);

(3) This example returns an empty string for the last condition.

var n = @GetNumberField("//field3");
@If(
	n > 0, @Return("Positive number"),
	// else if
	n < 0, @Return("Negative number"),
	// else
	@Return()
);

(4) This example demonstrates returning from a function.

function testNumber() {
var n = @GetNumberField("//field3");
@If(
	n > 0, @Return("Positive number"),
	// else if
	n < 0, @Return("Negative number"),
	// else
	@Return("Zero")
);
}

@Return("testNumber = " + testNumber());