How to pass data from one code step to another code step?
- Getting Started
- Bot Building
- Smart Agent Chat
- Conversation Design
-
Developer Guides
Code Step Integration Static Step Integration Shopify Integration SETU Integration Exotel Integration CIBIL integration Freshdesk KMS Integration PayU Integration Zendesk Guide Integration Twilio Integration Razorpay Integration LeadSquared Integration USU(Unymira) Integration Helo(VivaConnect) Integration Salesforce KMS Integration Stripe Integration PayPal Integration CleverTap Integration Fynd Integration HubSpot Integration Magento Integration WooCommerce Integration Microsoft Dynamics 365 Integration
- Deployment
- External Agent Tool Setup
- Analytics & Reporting
- Notifications
- Commerce Plus
- Troubleshooting Guides
- Release Notes
Table of Contents
How do you pass the data from one code step to another?Storing the data in a code stepRetrieving the stored data from the code stepEvery time we use a code step, it comes with a code, that enables the code step to function properly. At times, we might have to use multiple code steps, since every code step serves a certain purpose. It is not advisable to have all the functionalities embedded in a single code step as it might get confusing.
It might happen that, you are on a particular code step, and you want to use the data that is stored in another code step, so how do you do that?
How do you pass the data from one code step to another?
The data is stored in the conversation_details variable of a code step. You can pass data from one code step to another using this global variable. conversation_details acts as a common store between all the code steps. The data stored in conversation_details is shared between all the code steps in the bot.
conversation_details is made available to the users in the code step, in the following way -
conversation_details = body.get('conversation_details')
There are two main steps here, that we need to take care of -
- Storing the data in a code step.
- Retrieving the stored data from the code step.
Storing the data in a code step
Consider, you want to store an email id. You can do it by storing the email id in the conversation_details variable as shown below. You need to give a key and value pair at the time of storing the data.
Here, email_id is the key, and abc@rmail.com is the value.
conversation_details = body.get('conversation_details')
conversation_details["email_id"]="abc@rmail.com"
Retrieving the stored data from the code step
To retrieve the data that has been stored in a code step, assign the conversation_details to a variable, in this case, retrieve_email_id. This way you can retrieve the data from the code step.
conversation_details = body.get('conversation_details')
retrieve_email_id = conversation_details["email_id"]