cancel
Showing results for 
Search instead for 
Did you mean: 

"Constant" variable type

There is a need to have a "constant" variable - one that has global scope, but cannot be changed once it is defined.  In all other ways, it can be accessed as a global variable (one created with Set()), but also is allowed for things that require constant strings (or other values) today, such as Match()IsMatch(), MatchAll() which today cannot have variables for some of the arguments (ie: match string in these cases).

 

Recommendation would be to add a Define() function that allows defining a constant.  Once a constant is declared with Define() it would not be able to be modified (either by Define() and never with Set()), but otherwise be accessible as a standard global variable (additionally being able to be used in other formulas that require a constant string or other expression today).

 

Example:

 

Define( APP_NAME, "My Test Application" );
Define( MatchEmailPattern, "<(?<email>" & Match.Email & ")>" );
Define( MatchISO8601DurationPattern, "PT(?:(<hours>\d+)H)?(?:(?<minutes>\d+)M)?(?:(?<seconds>\d+)S)?" );

 The above (once executed) could then have the constants used anywhere in the application, ie:

//  CustomerEmail, ActionDuration, previously defined, and match patterns defined as in previous code block

If( !IsMatch( CustomerEmail, MatchEmailPattern ),
    Notify( "Provided customer email address: '" & CustomerEmail & "' is not valid.", NotificationType.Error )
); // If()

If( IsMatch( ActionDuration, MatchISO8601DurationPattern ),
    Update( 'App Log', { Time: Now(), Duration: ActionDuration, Application: APP_NAME, Text: "The operation completed successfully." } )
);

Status: New