Declaration Statements

Declaration statements allow you to introduce new variables, objects, or functions into your script. The keywords for these statements are: 

  • ASSIGN: Use this statement when you need to create a variable or a string array.
  • DYNAMIC: Use this statement when you need to create a dynamic data object.
  • FUNCTION: Use this statement to create a new function in your script.

The discussion of each type of statement includes a syntax summary. These summaries use certain conventions to indicate the parts of the statement and whether each part is required or optional.

ASSIGN Statements

Description: ASSIGN statements create a variable with the name and value you specify.

Syntax: ASSIGN <variable> = "<value>" | <value>

Studio Action: Assign

Details: ASSIGN statements create a <variable> and assigns a <value> to it. You don't need to declare a data type when you create a variable, unless it's a date/time type. Variables in Studio are implicity typed, which means you can create and assign a value in one step. For example: 

ASSIGN oneName = "Odin"

If the value you're assigning to a variable is numeric, you don't need to enclose it in double quotes. If the value is a string, it must be enclosed in double quotes.

You can use ASSIGN statements to create a string array:

ASSIGN manyNames = "Odin|Freya|Thor"

You can assign one variable as the value for another variable: 


ASSIGN x =  1
ASSIGN y = x 
ASSIGN var1 = z

The variable on the right side of the equal sign doesn't need to be enclosed in curly braces and double quotes if the variable is already declared. The script evaluates the term on the right side of the equal sign. If it's not in curly braces and double quotes and it's not numeric, the script assumes it's a variable. If it already exists, the script assigns its value to the second variable. If it isn't declared, the script creates it with a null value.

You can assign a value to a dynamic object member using ASSIGN. After you declare the object with DYNAMIC, use ASSIGN to assign values to the object's members. If the member doesn't already exist, it's created when you assign a value to it. Use this syntax: ASSIGN <name>.<key> = <value>

Using the ASSIGN keyword when declaring a variable or is not required. However, it's helpful to use it. Including ASSIGN makes the place in your script where you introduced the variable or array easy to locate using Advanced Search. Without ASSIGN, you must search for the name of the variable or array. The search results will contain every reference to the variable or array in your script. When you include ASSIGN in your search term, the search returns only the results where the variable is explicitly assigned. To declare a variable without ASSIGN, use this syntax: <name> = "<value>"

Naming Guidelines: Follow these guidelines when naming variables:

  • Use alpha-numeric characters (a-z, A-Z, 0-9).

  • The first character in the name must be a letter.
  • Use the underscore character ( _ ) and the dollar sign ( $ ) anywhere in the name.
  • If the last character in a variable name is a dollar sign, the value is treated as text.
  • Do not use the names of pre-defined variables or reserved words.

Learn More: More information about variables is available on the Variables help page.

DYNAMIC Statements

Description: DYNAMIC statements create a dynamic data object variable with the specified name.

Syntax: DYNAMIC <name>

Details: A dynamic data object is a variable that can hold multiple values. They're similar to arrays, but have some key differences.

The values that dynamic data objects hold are called parameters. They're defined as key-value pairs, where every parameter has a key (name) and a value. After you declare the object with the DYNAMIC keyword, you can define object members.

For example: 

DYNAMIC beowulfCharacteristics
beowulfCharacteristics.name = "Beowulf"
beowulfCharacteristics.occupation= "Hero" 
beowulfCharacteristics.foe = "Grendel" 

Case matters when referencing dynamic data objects and their parameters. BeowulfCharacteristics is not the same as beowulfCharacteristics.

If the value you're assigning to an object is numeric, you don't need to enclose it in double quotes. If the value is a string, it must be enclosed in double quotes.

Use DYNAMIC to declare any objects that are passed into your script from other scripts or integrations. Objects must be declared in every script or it causes a script validation error when you save.

Naming Guidelines: When naming dynamic data objects, follow these guidelines: 

  • Use alpha-numeric characters (a-z, A-Z, 0-9).

  • The first character in the name must be a letter.
  • Use the underscore character ( _ ) and the dollar sign ( $ ) anywhere in the name.
  • Do not use the names of pre-defined variables or reserved words.

Learn More: More information about dynamic data objects is available on the Objects and Data Structures help pages.

DYNAMIC has another important use, which is to create declaration statements for objects that are passed into the script from other sources. If you don't declare these objects, it causes an error when the script is saved. .

FUNCTION Statements

Description: Creates a custom function.

Syntax to declare: FUNCTION <name><([parameter], [...])> <{ ... [RETURN [data]]}>

Syntax to call: <functionName><([parameter], [parameter], [...])><{<varName>.<functionName><([parameter], [parameter], [...])>}>

Details: Declare a function by giving it a <name> with a set of open and closed parentheses at the end. For example, FUNCTION functionName(). Add optional [parameters] between the parentheses. Parameters allow you to pass data, called arguments, into and out of the function.

Between the curly braces { RETURN <data>} after the declaration header, include the code you want the script to execute when the function is called. End the code with the RETURN keyword followed by the variable <data> you want to hold the function's output. Including a variable after RETURN is required only if you need to pass data back to the calling script.

Function names must always include the parentheses, even if the function does not have parameters. For example: 

FUNCTION noParams()

FUNCTION twoParams(name, accountNum)

You can call a function in your script where you need to use the code that it contains. Which syntax you use to call the function depends on whether the function returns a value.

If the function definition has <parameters>, the script must pass the appropriate information into the function. You must include the parameters in the function call. Include all parameters in the same order they appear in the function definition . For example, callVar.twoParams('Beowulf', 349839)

If you want the result of the function to be assigned to a variable, you can call the function as part of an ASSIGN statement. For example, ASSIGN var = otherVar.function(). However, there is one case where this does not work, and that is to call a member function of the GetRESTproxy() function.

Add a comment after the function name in the function definition to provide IntelliPrompt help for the function. IntelliPrompt offers suggestions in pop-up menus as you type in the Snippet Editor window.

Naming Guidelines: When naming functions, follow these guidelines:

  • Use alpha-numeric characters (a-z, A-Z, 0-9).

  • The first character in the name must be a letter.
  • Use the underscore character ( _ ) and the dollar sign ( $ ) anywhere in the name.
  • Do not use reserved words or the names of built-in functions.

Learn More: More information about functions is available on the Functions help page.

Example

FUNCTION TimerRound(Timer)
{
  IF Timer = "-1"
  {
    ASSIGN Timer = Timer
  }
  ELSE
  {
    ASSIGN PeriodLocation = Timer.indexof('.')
	IF PeriodLocation = 0
	{
	  ASSIGN Timer = Timer
	}
	ELSE
	{
	    ASSIGN DataLength = Timer.length
	    IF DataLength - PeriodLocation <= 2
	        {
	          ASSIGN Timer = Timer
            }   
	    ELSE
	     {
            ASSIGN DigitCheck = Timer.substr(PeriodLocation + 3, PeriodLocation + 3)
            IF DigitCheck >=5 && DigitCheck <= 9
               {
                  ASSIGN Timer = Timer + .01
               }
            ELSE
              {
                 ASSIGN Timer = Timer
              }
		
            ASSIGN Timer = Timer.substr(1, PeriodLocation + 2)
         }
      }
   }
  
   TRACE "{Timer}"
   RETURN Timer
}

IF TEST = 1
   {
      ASSIGN DC1 = "1.931876668494874"
   }   

   ASSIGN DC1 = TimerRound(DC1)