IsDefined

Determine whether a given variable reference exists.

For example:

  • isDefined( "luis" ) will test for the existence of an lmajano variable in any accessible scope.

  • isDefined( "variables.foo" ) will test for the existence of a foo variable in the variables scope.

  • isDefined( "brad.age" ) will test for the existence of an age key in the brad struct, in any accessible scope

Method Signature

IsDefined(variable=[string])

Arguments

Argument
Type
Required
Description
Default

variable

string

true

The variable reference to test for existence. For security reasons, only dot-notation is supported. Struct/array bracket notation is not supported, nor is function invocation, etc.

Examples

Using IsDefined

Checking for the existence of a form variable.

<bx:if isDefined( "form.submit" ) >...</bx:if>

Scope Evaluation Order and Unscoped Variables

Beware of scope evaluation order when checking for an unscoped variable name.

Run Example

url.FOO = "url.foo";
form.FOO = "form.foo";
writeoutput( "Is 'foo' defined? " & isDefined( "foo" ) );
writeoutput( isDefined( "foo" ) ? " (" & foo & ")" : "" );

Result: Is 'foo' defined? YES (url.foo)

Dot-notation Variable Names

Potentially unexpected behavior when checking for a dot-notation variable containing a scope name.

Run Example

local[ "form.submit" ] = "local['form.submit']";
form.SUBMIT = "form.submit";
writeoutput( "Is 'form.submit' defined?" & isDefined( "form.submit" ) );
writeoutput( isDefined( "form.submit" ) ? " (" & form.SUBMIT & ")" : "" );
writeoutput( "<br>" );
writeoutput( "Is 'submit' defined? " & isDefined( "submit" ) );
writeoutput( isDefined( "submit" ) ? " (" & submit & ")" : "" );

Result: Is 'form.submit' defined? YES (local['form.submit']) Is 'submit' defined? YES(form.submit)

Additional Examples

Run Example

// using isDefined with condition statement
if( isDefined( "form.reset" ) ) {
	// Code to be Executed

}
str = {};
str.VALUE = "test";
writeDump( isDefined( "str.value" ) );
 // true

Last updated

Was this helpful?