cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
5670
Views
13
Helpful
14
Replies

CVP 11.0 Local Variables. Example needed.

e.gailiss
Level 4
Level 4

Has anybody played with "Local Variables" and can give me a sample how to work with them?

I'm looking for a way how to create them, read and change values.

I'm trying to create element that reads file, parses it's content and stores values in "local variables".  Maybe built-in Math->Set Value element is good enough, but as I understand it can store single variable in one go (one Javascript code block per variable) . Since I'm parsing file content, I don't like to do it multiple times (once per variable).

Thanks!

1 Accepted Solution

Accepted Solutions

Ervins,

Not used them myself yet but there's a couple of new methods to get and set local variables. 

com.​audium.​server.​session.​APIBase

public void setLocalVariableData(String variableName, Object value)

com.​audium.​server.​session.​ComponentAPI

public Object getLocalVariableData(String variableName)

Paul

View solution in original post

14 Replies 14

ewindgat
Level 5
Level 5

if you mean call variables, something like this...

var callVars = dialog.getMediaProperties();

Then, access ECC variables like this:

somevariable = callVars["user.ecc_variable_name"];


set a variable

var options = {};
  
currdialog.updateCallVariable(name, value, options);

No, I mean "local variables". A new feature in CVP Call Studio 11.0. you can create/set them using Math>Set Value element.

Example you've given looks like JavaScript from Finesse gadget. It's not what I'm looking for. Example I'm looking for would be in Java.

janinegraves
Spotlight
Spotlight

I've used the SetValue element to create Local Variables - you can enter any JavaScript you want into the LocalVariables value field.

Right-click in the Settings tab and select Add Variable. You'll get a field where you can define a var name. For example: TestVar

Then click the ... button to enter one or more lines of JavaScript. Only the very last line of the code will be assigned into the Local Variable named TestVar.

For example, I have a Session Variable named FullName that is of the format LastName,FirstName  (ex: Graves,Janine)

That I want to split at the comma.

I created a Local Variable named Position  and set its value to this   {Data..Session.FullName}.indexOf(",");

Then I can also add another Local Variable in that element, named LastName

Set the Value to  {Data..Session.FullName}.substr(0, {LocalVar.Position});

And I can also add another Local Variable in that element, named FirstName

Set the Value to  {Data..Session.FullName}.slice({LocalVar.Position}+1);

You can also execute multiple statements (semi-colon separated) within the value field, but I believe only the final statement's value will be assigned into the LocalVariable.

Also, LocalVariables don't display in the Studio Debugger. So if you want to display the result, you could assign the LocalVariables into Session Variables.

Janine

Here is some more examples:

Different Types of Variables:

 

  1. 1. In addition to elements, the application can define and access following types of variables:
  2. a. Session variables : The same as provided in CallStudio today. Scope will be session-wide and visible in all applications accessing that call session. Life will be same as call session. It will be referred with "session." prefix. Currently the variables can be accessed only within element data tab.
  3. b. Application variables: Scope will be application-wide(not application instance). e.g. One can maintain a counter for the whole application. It will be visible only within a particular application but to all sessions. Life will be till the application is restarted. It will be referred with "application." prefix.
  4. c. Global variables: Scope will be system wide. It will be visible to all app instances and all sessions. Life will be till the system/vxml server is restarted. It will be referred with "system." prefix.
  5. d. Element Data: Scope of element data is flow wide and is visible within main flow or Subflow. Life will be until the flow is valid.
  6. e. Local variables : Scope, Life and namespace will be within the Flow (main or Subflow). They will not have any prefix.
  7. 2. Naming

             

All the user defined variables at session, application and system level will have additional user prefix. e.g. system.user., application.user. , session.user. etc. Any variables without .user., will be treated as immutable variables and can not be modified.

 

  1. 3. Data sharing between flows
  2. 1. The sharing of values between flows (caller and called) will happen using session/application/global data or parameter/return value passing.
  3. 2. Elements of one flow will not be visible in any other flow.
  4. 3. Life/Scope of elements and variables local to a flow, will be limited to that flow only.
  5. 4. The values of variables will be manipulated using a new Element, SetValue, which will provide an assignment operator and implicit object creator. This will be similar to the "var" concept in Javascript.

         

Subflow Parameter Passing and Return value handling:

 

  1. 1. Parameter Passing
  2. 1. A subflow start node can have multiple data values starting with name Param. e.g. Param1, Param2 etc
  3. 2. The Caller node can have multiple data values starting with name Param.
    3. When a subflow is called, the caller will set the same name attributes for the startnode of the subflow, for all the data values whose names match mutually. So subflow-start.Param1 will be caller.Param1 and so on.

     

This approach of setting the parameter will help separating the access of elements and avoiding the subflow access caller flow elements.

 

This will provide the flexibility of each element being defined independently and linked by the programmer at some later point. As we need the member variables to be available at app development time itself, so that they can be referred within the flow, dynamic creation of the list from subflow-start node to caller node or vice-versa will not be able to handle that and has not been chosen.

 

  1. 4. All the subflow elements can access the parameters using Data.Element.Startflow.Param1 etc.
    5. While validating, check that the parameters referred for the StartFlow Element is present in the caller node. (Low priority).
  2. 2. Return values
  3. 1. The return element of the subflow can have multiple data values with names starting with RetVal.
  4. 2. The caller element will also have same set of data values defined with names starting with RetVal.
  5. 3. When the subflow returns, the same element names will be assigned in the caller node.
    4. While validating, check that the parameters referred for the caller node are defined in the Return node of the called subflow.
  6. 3. Subflow as a namespace:
  7. 1. Backend - element config should be separate for each subflow or indexed by subflow, elemname combo.
  8. 2. Name validation should check only within subflow instead of all callflows
  9. 3. The elements of a subflow will be only visible to the elements in the same subflow. The Element tab drop down should only show the elements of the subflow.

                 

Local Variables

 

  1. 1. A "SetValue" action element will be created, which will have two attributes.

 

varname - This will be the LHS of the expression. If the variable is not created so far, it will be created. [A new hash map will be  created for each subflow, with key as the var name and value as a string. The hashmap is deleted when the subflow returns.]

 

expression   - This will be RHS of the expression, which will be evaluated and assigned to the variable.
2. On execution of the SetValue element, it will take the expression as the input and create an entry in the hashmap with the variable name as the key, if it does not exist and assign the value.

 

  1. 3. Local variable can be referred within expressions, i.e. element data members or when setting another varaible, as Var.<NAME>. When it is referred, the controller will substitute the value from the hashmap entry with the same name.
    4. If an undefined variable is refferred, then ??? (What happens if we refer to an element data when the element is not executed yet). Replace with zero or empty string.

    5. Validation : Variable used in element data substitutions or any other expression is defined within the subflow at some point, using SetValue.

 

global / application / session variable

 

  1. 1.    SetValue action element can be used to set and create global/application/session variables. In Setvalue LHS, if the variables with "session." or "application" or "global" prefix is used, they also should have ".user." as their middle name part. Any other prefix will be treated as a local variable.
    2. global., application., session. prefix are used to denote the type of variable. No prefix indicates local variable.
    3. If the global/application/session variable is used in an expression and it does not exist, then value will be taken as 0 or "" depending on the context.
    4. To ensure that the same values can be used in the expressions, the variable creation and evaluation and assignment will be done with a lock.

 

I'm sorry but this answer is to a different question, not to the one I asked.

I am looking for a piece of Java code that would allow me to create & set local variable from my own custom element.

So far there is information how to work with "Set Value" element. I'm building my own element and would like to work create/work with local variables from within that element.

Ervins,

Not used them myself yet but there's a couple of new methods to get and set local variables. 

com.​audium.​server.​session.​APIBase

public void setLocalVariableData(String variableName, Object value)

com.​audium.​server.​session.​ComponentAPI

public Object getLocalVariableData(String variableName)

Paul

Thanks, Paul !

This is something I can work from.

Is there a new version of JavaDoc for CVP element classes? The only version I can find on developer.cisco.com is for CVP version 9.

Thank you!

Ervins

Have a look in Cisco\CVP\VXMLServer\docs\javadocs

Got it. Thanks!

Question for you Janine. When you use Set Value with  {Data..Session.FullName}.substr(0, {LocalVar.Position});,

How do you go Extract the value that is derived?

 

Since you set the Position to =  {Data..Session.FullName}.substr(0, {LocalVar.Position}); does that mean the result would be stored in the {Data.Session.Position} or like {Data.Element.Set_Value.value}?

You can use "eval" 

 

Example below:

var str = {Data.Session.pin};
eval(str.length);

 

Hello Gouroke,

     I don't think I understand what you mean. So once I use the SET Value Element, create a name called "var" with value of 

str = {Data.Session.pin};
eval(str.length);

Then how do I get the output put into a session or element data?

Boddol,

 

Below is a screen shot of setting a Local variable "PIN_Length", which has a value of 

var str = {Data.Session.pin}; eval(str.length);


PIN_Length.JPG

 

A local Variable is similar to a session variable but you use "LocalVar" instead of "Session" to retrieve it e.g. {LocalVar.PIN_Length}.

 

You can use the subsitution tag builder as per below.

 

LocalVariable.JPG

 

Regards,

Gerry

Thanks. That worked.

Getting Started

Find answers to your questions by entering keywords or phrases in the Search bar above. New here? Use these resources to familiarize yourself with the community: