IsDefined
Determine whether a given variable reference exists.
For example:
isDefined( "luis" )
will test for the existence of anlmajano
variable in any accessible scope.isDefined( "variables.foo" )
will test for the existence of afoo
variable in thevariables
scope.isDefined( "brad.age" )
will test for the existence of anage
key in thebrad
struct, in any accessible scope
Method Signature
IsDefined(variable=[string])
Arguments
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.
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.
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
// using isDefined with condition statement
if( isDefined( "form.reset" ) ) {
// Code to be Executed
}
str = {};
str.VALUE = "test";
writeDump( isDefined( "str.value" ) );
// true
Related
Last updated
Was this helpful?