Please enable JavaScript to view this site.

ESL Documentation

The add action statement allows you to create a new object. In the add statement, you define an object exactly as you would in a regular object definition. The new object is created when the add statement is executed. (Be careful not to confuse the add action statement with the add to action statement, which adds contents to an existing object.)

 

The add statement is commonly used when you do not know how many objects you will be creating. For example, you might want to create an object for each line of input that ESL receives from an application, as shown in the example below:

 

response to line from application

    extract from input

        take word Name

        take number X

        take number Y

    add key Name at position X Y

        pattern KeyPattern

 

ESL extracts fields from an input line received from an application and stores them in the variables called Name, X, and Y. For example, if the application sends the following text:

 

A3 216 516

 

ESL extracts a word, A3, which becomes the value of the variable Name. The numbers 216 and 516 are extracted and stored as the values of the X and Y variables. The add statement creates a new key whose name is A3 and whose position is 216 516. Each time ESL matches the input to the specified control string, new values are extracted for the Name, X, and Y variables, and a new object is created.

 

When adding an object during runtime, be careful to ensure that the program does not create multiple objects with the same name. This can happen when a response is executed multiple times. To minimize this risk, specify a variable, rather than an explicit object name, in the add statement. (The above example does this.)

 

You can add an object to a class of objects with an add to class

statement, described in Using Classes of Objects.