How to Use Entity Values on Code Step

Using Entities on Code Editor

The information which is collected from users on the Static Step, in the form of entities, can be used on Code Step to fetch user-related information.

The connection is automatic from Static Step to Code Step i.e. whenever the user provides all the mandatory entity values, the following Code Step gets triggered. In order to use these entity values in the Code Step, we have to create new variables.

Let's take the example of fetching order details. We have an entity to save Order ID. We would use this to understand how to fetch information using entity value on Code Step -

order_id_demotrain is a regex entity with the pattern ^[a-z]{3}\d{3}$, this entity will accept values such as abc123.

There is a standard JSON format in which the values are stored within an entity. To understand this format, open the Detailed Info tab on the logs sections besides the entity value which was provided to the IVA. This is found on the Test Bot as shown below -

So the Order ID is stored under the entity name order_id_demotrain. The actual value is stored under entity_value. On Code Step, you can fetch the value in this format -

order_id = entities.get("order_id_demotrain")[0].get("entity_value").get('value')

The above example is using a regex type entity. The format in which entity is stored changes for every type of entity. Please check the Debug log section to know the format in which the entity is stored to use them on Code Step.


Can’t find what you’re looking for? Email us at support@haptik.ai.