Convert a string value to a typed value
Within a call flow, it is not uncommon for flow authors to want to convert a string value in to a typed value. For many basic data types, Architect supports converting a string value to another type.
The following scenario illustrates the problem a flow author may encounter when trying to convert a string value of “5” that, at runtime, returns the integer value of 5.
In this example, the flow must convert a string to a network-based data type. The flow wants to transfer a call to a queue, and calls a Bridge action to retrieve the name of the queue. The Bridge action returns the queue name in a string. A Transfer to ACD action will perform the transfer to queue.
If a flow author tries to use the string as a queue setting directly on the Transfer to ACD action, the system returns an error. The Transfer to ACD action expects the system to supply a queue value for the queue transfer destination. Because the To functions convert one type to another, the flow author may try to use the ToQueue function to convert the string over to a queue using the ToQueue function. However, because Architect does not have a ToQueue implementation that converts a string value to a queue value, you cannot convert strings to network-based data types in a flow:
In Architect, use parallel arrays to convert a string value to another value type. Because this solution effectively sets up a key > value mapping, and the specified values are unlimited, it works beyond network-based value types.
For example, a flow contains a string collection variable called Task.QueueNames, and a queue collection variable named Task.Queues. The number of items in both collections is the same. You can configure the variables to quickly look up the associated queue in Task.Queues for a string value found in Task.QueueNames.
Use an Update Data action to configure the collections set on these variables:
|Genesys Cloud sales queue
|Genesys Cloud marketing queue
|Genesys Cloud technical support queue
Next, build an expression to perform the lookup and has a fallback default queue if the system cannot find the string supplied for the lookup conversion. To begin, set Task.DefaultQueue to the Genesys Cloud Operator queue for this organization.
Now, build the expression that looks up the queue by name and returns the queue associated with that string:
If(FindFirst(Task.QueueNames, Task.QueueNameStr)!=-1, Task.Queues[FindFirst(Task.QueueNames, Task.QueueNameStr)], Task.DefaultQueue)
Now, you can map string values to queues in a call flow. The expression above works for collections that have a small number of items. For larger collections, save the value from the FindFirst call to a variable, which ensures the system does not execute the call twice in the same expression. If you save the value of the FindFirst call to a Task.FoundIndex integer variable, rewrite the above expression as:
If(Task.FoundIndex!=-1, Task.Queues[Task.FoundIndex], Task.DefaultQueue)
Currently, Architect does not include a built-in function that converts a string to a network-based type. Architect does not support this function for various reasons:
- At call flow runtime the resolution of a network-based data type, for example a queue from a string, currently requires a round trip from the edge to the cloud. This scenario can potentially create a lot of network traffic.
- An edge may run while disconnected. In this case, runtime resolution of a string value to a network based value is not possible by calling the cloud.
- In the rare case of two network based objects with the same name, lookup by name becomes ambiguous because the system could return two or more objects with the same name.
However, you can use the various Find and Get actions that allow you to perform search and lookup operations. For more information, see Task and state editor actions.