{"id":24061,"date":"2020-07-17T13:03:52","date_gmt":"2020-07-17T12:03:52","guid":{"rendered":"https:\/\/developer.kore.ai\/v10-1\/?p=24061"},"modified":"2022-03-30T15:30:35","modified_gmt":"2022-03-30T14:30:35","slug":"how-to-update-data-in-data-tables","status":"publish","type":"post","link":"https:\/\/developer.kore.ai\/v10-1\/docs\/bots\/how-tos\/how-to-update-data-in-data-tables\/","title":{"rendered":"Updating Data in Data Tables"},"content":{"rendered":"<section class=\"l-section wpb_row height_auto\"><div class=\"l-section-h i-cf\"><div class=\"g-cols vc_row type_default valign_top\"><div class=\"vc_col-sm-12 wpb_column vc_column_container\"><div class=\"vc_column-inner\"><div class=\"wpb_wrapper\">\r\n\t<div class=\"wpb_text_column \">\r\n\t\t<div class=\"wpb_wrapper\">\r\n\t\t\t<p>In this How-To, we will explore a scenario in a Banking Bot, where the account-related data for a customer is stored in a Data Table. We will see how the data can be updated by a request from the user.<\/p>\n<p>For details on what Data Tables are and how it is implemented in the Kore.ai Bots platform, <a href=\"\/docs\/bots\/advanced-topics\/data-as-a-service\/\" target=\"_blank\" rel=\"noopener noreferrer\">refer here<\/a>.<\/p>\n\r\n\t\t<\/div>\r\n\t<\/div>\r\n<div class=\"w-separator size_small with_line width_default thick_1 style_solid color_border align_center\"><div class=\"w-separator-h\"><\/div><\/div>\r\n\t<div class=\"wpb_text_column \">\r\n\t\t<div class=\"wpb_wrapper\">\r\n\t\t\t<h1><span class=\"ez-toc-section\" id=\"Problem_Statement\">Problem Statement<\/span><\/h1>\n<p>Consider a Banking Bot, for a given customer, the following data is stored. This data needs to be updated as per customer request. Customers can update only email id and address details.<\/p>\n<ol>\n<li>Id;<\/li>\n<li>Name;<\/li>\n<li>Email id;<\/li>\n<li>Address; and<\/li>\n<li>Type<\/li>\n<\/ol>\n<p><a ref=\"magnificPopup\" href=\"https:\/\/kore-wordpress.s3.us-east-2.amazonaws.com\/developer.kore.ai\/v10-1\/wp-content\/uploads\/sites\/35\/20200715095245\/DTUC_table.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-24026\" src=\"https:\/\/kore-wordpress.s3.us-east-2.amazonaws.com\/developer.kore.ai\/v10-1\/wp-content\/uploads\/sites\/35\/20200715095245\/DTUC_table.png\" alt=\"\" width=\"1091\" height=\"557\" srcset=\"https:\/\/kore-wordpress.s3.us-east-2.amazonaws.com\/developer.kore.ai\/v10-1\/wp-content\/uploads\/sites\/35\/20200715095245\/DTUC_table.png 1091w, https:\/\/kore-wordpress.s3.us-east-2.amazonaws.com\/developer.kore.ai\/v10-1\/wp-content\/uploads\/sites\/35\/20200715095245\/DTUC_table-300x153.png 300w, https:\/\/kore-wordpress.s3.us-east-2.amazonaws.com\/developer.kore.ai\/v10-1\/wp-content\/uploads\/sites\/35\/20200715095245\/DTUC_table-1024x523.png 1024w\" sizes=\"auto, (max-width: 1091px) 100vw, 1091px\" \/><\/a><\/p>\n\r\n\t\t<\/div>\r\n\t<\/div>\r\n<div class=\"w-separator size_small with_line width_default thick_1 style_solid color_border align_center\"><div class=\"w-separator-h\"><\/div><\/div>\r\n\t<div class=\"wpb_text_column \">\r\n\t\t<div class=\"wpb_wrapper\">\r\n\t\t\t<h2><span class=\"ez-toc-section\" id=\"Pre-requisites\">Pre-requisites<\/span><\/h2>\n<ul>\n<li>Bot building knowledge;<\/li>\n<li>A Banking Bot with access to the above-mentioned table, and data existing in that table (<a href=\"\/docs\/bots\/how-tos\/how-to-add-data-tables\/\">refer here<\/a> for use case example to create and add data).<\/li>\n<\/ul>\n\r\n\t\t<\/div>\r\n\t<\/div>\r\n<div class=\"w-separator size_small with_line width_default thick_1 style_solid color_border align_center\"><div class=\"w-separator-h\"><\/div><\/div>\r\n\t<div class=\"wpb_text_column \">\r\n\t\t<div class=\"wpb_wrapper\">\r\n\t\t\t<h1><span class=\"ez-toc-section\" id=\"Configurations\">Configurations<\/span><\/h1>\n<p>Let us consider each of the following scenarios one by one:<\/p>\n<ol>\n<li>Dialog Task to:\n<ol>\n<li>gather required information; and<\/li>\n<li>invoke a service to update the customer information.<\/li>\n<\/ol>\n<\/li>\n<\/ol>\n\r\n\t\t<\/div>\r\n\t<\/div>\r\n\r\n\t<div class=\"wpb_text_column \">\r\n\t\t<div class=\"wpb_wrapper\">\r\n\t\t\t<h2><span class=\"ez-toc-section\" id=\"Dialog_Task_Configuration\">Dialog Task Configuration<\/span><\/h2>\n<p>We will be creating a dialog task to gather the required information, and use a Service node to update the data table with the values thus gathered.<\/p>\n<p><a ref=\"magnificPopup\" href=\"https:\/\/kore-wordpress.s3.us-east-2.amazonaws.com\/developer.kore.ai\/v10-1\/wp-content\/uploads\/sites\/35\/20200717135702\/DTUC2_dialog.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-24064\" src=\"https:\/\/kore-wordpress.s3.us-east-2.amazonaws.com\/developer.kore.ai\/v10-1\/wp-content\/uploads\/sites\/35\/20200717135702\/DTUC2_dialog.png\" alt=\"\" width=\"1277\" height=\"563\" srcset=\"https:\/\/kore-wordpress.s3.us-east-2.amazonaws.com\/developer.kore.ai\/v10-1\/wp-content\/uploads\/sites\/35\/20200717135702\/DTUC2_dialog.png 1277w, https:\/\/kore-wordpress.s3.us-east-2.amazonaws.com\/developer.kore.ai\/v10-1\/wp-content\/uploads\/sites\/35\/20200717135702\/DTUC2_dialog-300x132.png 300w, https:\/\/kore-wordpress.s3.us-east-2.amazonaws.com\/developer.kore.ai\/v10-1\/wp-content\/uploads\/sites\/35\/20200717135702\/DTUC2_dialog-1024x451.png 1024w\" sizes=\"auto, (max-width: 1277px) 100vw, 1277px\" \/><\/a><\/p>\n<h3><span class=\"ez-toc-section\" id=\"Create_Dialog_Task\">Create Dialog Task<\/span><\/h3>\n<ol>\n<li>From the left navigation menu, select\u00a0<strong>Bot Tasks -&gt; Dialog Tasks.<\/strong><\/li>\n<li>Click the\u00a0<strong>+<\/strong> against the\u00a0<strong>Dialog Tasks<\/strong> to create a new Task\n<ul>\n<li>Enter\u00a0<strong>IntentName<\/strong>, say, <em>UpdateCustomer<\/em><\/li>\n<li><strong>Create &amp; Proceed<\/strong> to open the dialog builder page.<\/li>\n<\/ul>\n<\/li>\n<li>Retain the Intent Node default settings, and close the Intent Node.<\/li>\n<li>Click the\u00a0<strong>+<\/strong> next to the intent node and add an <strong>Entities<\/strong> to capture the customer id:<br \/>\n<table>\n<tbody>\n<tr>\n<th>Entity Name<\/th>\n<th>Type<\/th>\n<th>User Prompts<\/th>\n<\/tr>\n<tr>\n<td>CustId<\/td>\n<td>String<\/td>\n<td>Enter your customer id<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/li>\n<li>First, we will fetch data from the table for the given Cust Id and then use a Logic node to control the process flow.<\/li>\n<\/ol>\n\r\n\t\t<\/div>\r\n\t<\/div>\r\n\r\n\t<div class=\"wpb_text_column \">\r\n\t\t<div class=\"wpb_wrapper\">\r\n\t\t\t<h3><span class=\"ez-toc-section\" id=\"Fetch_Data\">Fetch Data<\/span><\/h3>\n<p>You can use a Service call to fetch data from the table:<\/p>\n<ol>\n<li>Click the\u00a0<strong>+<\/strong> against the entity node.<\/li>\n<li>Select\u00a0<strong>Service -&gt; New Service Node<\/strong> option.<\/li>\n<li>From the\u00a0<strong>General Settings<\/strong> section configure the following:\n<ul>\n<li><strong>Name<\/strong> say <em>GetCustomerData<\/em><\/li>\n<li><strong>Display Name<\/strong> say <em>Get Customer Data<\/em><\/li>\n<li><strong>Service Type<\/strong> select\u00a0<em>Data Service<\/em><\/li>\n<li><strong>Type<\/strong> select\u00a0<em>Table<\/em><\/li>\n<\/ul>\n<\/li>\n<li>Under\u00a0<strong>Request Definition<\/strong> click\u00a0<strong>Add Request<\/strong> to define a request to fetch data from the table.<\/li>\n<li>In the <strong>Data Service Request Definition<\/strong> page, enter the following:\n<ul>\n<li><strong>Choose Table Name<\/strong> as <em>customertable<\/em><\/li>\n<li><strong>Actions<\/strong> as <em>Get Data<\/em><\/li>\n<li><strong>Choose Filters<\/strong> to select the <em>CustId = {{context.entities.CustId}}<\/em><\/li>\n<\/ul>\n<p><a ref=\"magnificPopup\" href=\"https:\/\/kore-wordpress.s3.us-east-2.amazonaws.com\/developer.kore.ai\/v10-1\/wp-content\/uploads\/sites\/35\/20200720052633\/DTUC2_fetch.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-24068\" src=\"https:\/\/kore-wordpress.s3.us-east-2.amazonaws.com\/developer.kore.ai\/v10-1\/wp-content\/uploads\/sites\/35\/20200720052633\/DTUC2_fetch.png\" alt=\"\" width=\"697\" height=\"763\" srcset=\"https:\/\/kore-wordpress.s3.us-east-2.amazonaws.com\/developer.kore.ai\/v10-1\/wp-content\/uploads\/sites\/35\/20200720052633\/DTUC2_fetch.png 697w, https:\/\/kore-wordpress.s3.us-east-2.amazonaws.com\/developer.kore.ai\/v10-1\/wp-content\/uploads\/sites\/35\/20200720052633\/DTUC2_fetch-274x300.png 274w\" sizes=\"auto, (max-width: 697px) 100vw, 697px\" \/><\/a><\/li>\n<li><strong>Save<\/strong> the definition and\u00a0<strong>close<\/strong> the service node.<\/li>\n<li>Add a\u00a0<strong>Message Node<\/strong> to display the records fetches using the following context variable values, since we are fetching only one record, we are using a static <em>[0]<\/em> reference to the row:<br \/>\n<code>'For the customer number entered, we have the following details: {{context.GetCustomerData.response.body.queryResult[0].CustName}}, {{context.GetCustomerData.response.body.queryResult[0].CustEmail}}, {{context.GetCustomerData.response.body.queryResult[0].Address}}, {{context.GetCustomerData.response.body.queryResult[0].CustType}}'<\/code><\/li>\n<\/ol>\n\r\n\t\t<\/div>\r\n\t<\/div>\r\n\r\n\t<div class=\"wpb_text_column \">\r\n\t\t<div class=\"wpb_wrapper\">\r\n\t\t\t<h3><span class=\"ez-toc-section\" id=\"Update_Data\">Update Data<\/span><\/h3>\n<p>We will be using an entity node and a logic node to capture the inputs from the customer and to control the process flow:<\/p>\n<ol>\n<li>Click the\u00a0<strong>+<\/strong> against the last message node added above.<\/li>\n<li>Select an\u00a0<strong>Entity Node<\/strong> and add a\u00a0<em>List of Items (enumerated)<\/em> type entity with the following settings.<br \/>\n<table>\n<tbody>\n<tr>\n<th>Display Name<\/th>\n<th>Value<\/th>\n<\/tr>\n<tr>\n<td>Email Id<\/td>\n<td>Email Id<\/td>\n<\/tr>\n<tr>\n<td>Address<\/td>\n<td>Address<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/li>\n<li>Add a\u00a0<strong>Logic Node<\/strong> and based upon the value from the entity node above fetch either Email ID or Address from the customer, here\u00a0<em>CustEmail<\/em> and\u00a0<em>CustAddress<\/em> are the entities to capture customer email id and customer address.<br \/>\n<a ref=\"magnificPopup\" href=\"https:\/\/kore-wordpress.s3.us-east-2.amazonaws.com\/developer.kore.ai\/v10-1\/wp-content\/uploads\/sites\/35\/20200720053210\/DTUC2_logic.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-24069\" src=\"https:\/\/kore-wordpress.s3.us-east-2.amazonaws.com\/developer.kore.ai\/v10-1\/wp-content\/uploads\/sites\/35\/20200720053210\/DTUC2_logic.png\" alt=\"\" width=\"825\" height=\"625\" srcset=\"https:\/\/kore-wordpress.s3.us-east-2.amazonaws.com\/developer.kore.ai\/v10-1\/wp-content\/uploads\/sites\/35\/20200720053210\/DTUC2_logic.png 825w, https:\/\/kore-wordpress.s3.us-east-2.amazonaws.com\/developer.kore.ai\/v10-1\/wp-content\/uploads\/sites\/35\/20200720053210\/DTUC2_logic-300x227.png 300w\" sizes=\"auto, (max-width: 825px) 100vw, 825px\" \/><\/a><\/li>\n<li>Also populate the context variables with the current details, these variables would be used to update the data table.<br \/>\n<a ref=\"magnificPopup\" href=\"https:\/\/kore-wordpress.s3.us-east-2.amazonaws.com\/developer.kore.ai\/v10-1\/wp-content\/uploads\/sites\/35\/20200720053331\/DTUC2_contextVar.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-24070\" src=\"https:\/\/kore-wordpress.s3.us-east-2.amazonaws.com\/developer.kore.ai\/v10-1\/wp-content\/uploads\/sites\/35\/20200720053331\/DTUC2_contextVar.png\" alt=\"\" width=\"827\" height=\"581\" srcset=\"https:\/\/kore-wordpress.s3.us-east-2.amazonaws.com\/developer.kore.ai\/v10-1\/wp-content\/uploads\/sites\/35\/20200720053331\/DTUC2_contextVar.png 827w, https:\/\/kore-wordpress.s3.us-east-2.amazonaws.com\/developer.kore.ai\/v10-1\/wp-content\/uploads\/sites\/35\/20200720053331\/DTUC2_contextVar-300x211.png 300w\" sizes=\"auto, (max-width: 827px) 100vw, 827px\" \/><\/a><\/li>\n<li>From the Email Id and Address entity trigger a\u00a0<strong>Script Node<\/strong> to modify the context variables appropriately using the following script:\n<pre>if (context.entities.CustUpdateChoice == 'Address') {\r\n    context.custAdd = context.entities.CustAddress;\r\n  }\r\nelse {\r\n   context.custEmail = context.entities.CustEmail;\r\n }<\/pre>\n<\/li>\n<li>Select\u00a0<strong>Service -&gt; New Service Node<\/strong> option.<\/li>\n<li>From the\u00a0<strong>General Settings<\/strong> section configure the following:\n<ul>\n<li><strong>Name<\/strong> say <em>UpdateCust<\/em><\/li>\n<li><strong>Display Name<\/strong> say <em>Update Customer Data<\/em><\/li>\n<li><strong>Service Type<\/strong> select\u00a0<em>Data Service<\/em><\/li>\n<li><strong>Type<\/strong> select\u00a0<em>Table<\/em><\/li>\n<\/ul>\n<\/li>\n<li>Under\u00a0<strong>Request Definition<\/strong> click\u00a0<strong>Add Request<\/strong> to define a request to add data to the table.<\/li>\n<li>In the <strong>Data Service Request Definition<\/strong> page, enter the following:\n<ul>\n<li><strong>Choose Table Name<\/strong> as <em>customertable<\/em> defined earlier<\/li>\n<li><strong>Actions<\/strong> as <em>Update Data<\/em><\/li>\n<li><strong>Assign Values<\/strong> from the entities defined as follows, remember you need to include all the fields and their values, else the field would be set to null value:<br \/>\n<table>\n<tbody>\n<tr>\n<th>Column<\/th>\n<th>Entity context<\/th>\n<\/tr>\n<tr>\n<td>CustName<\/td>\n<td>{{context.CustName}}<\/td>\n<\/tr>\n<tr>\n<td>CustEmail<\/td>\n<td>{{context.CustEmail}}<\/td>\n<\/tr>\n<tr>\n<td>Address<\/td>\n<td>{{context.CustAddress}}<\/td>\n<\/tr>\n<tr>\n<td>CustType<\/td>\n<td>{{context.CustType}}<\/td>\n<\/tr>\n<tr>\n<td>CustId<\/td>\n<td>{{context.CustId}}<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><a ref=\"magnificPopup\" href=\"https:\/\/kore-wordpress.s3.us-east-2.amazonaws.com\/developer.kore.ai\/v10-1\/wp-content\/uploads\/sites\/35\/20200720053700\/DTUC2_update.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-24071\" src=\"https:\/\/kore-wordpress.s3.us-east-2.amazonaws.com\/developer.kore.ai\/v10-1\/wp-content\/uploads\/sites\/35\/20200720053700\/DTUC2_update.png\" alt=\"\" width=\"701\" height=\"767\" srcset=\"https:\/\/kore-wordpress.s3.us-east-2.amazonaws.com\/developer.kore.ai\/v10-1\/wp-content\/uploads\/sites\/35\/20200720053700\/DTUC2_update.png 701w, https:\/\/kore-wordpress.s3.us-east-2.amazonaws.com\/developer.kore.ai\/v10-1\/wp-content\/uploads\/sites\/35\/20200720053700\/DTUC2_update-274x300.png 274w\" sizes=\"auto, (max-width: 701px) 100vw, 701px\" \/><\/a><\/li>\n<\/ul>\n<\/li>\n<li>Add a <strong>Message node<\/strong> to display the success message.<\/li>\n<li>Using <strong>Talk to bot<\/strong> option, enter the values when prompted and see the message being displayed.<\/li>\n<\/ol>\n\r\n\t\t<\/div>\r\n\t<\/div>\r\n<div class=\"w-separator size_small with_line width_default thick_1 style_solid color_border align_center\"><div class=\"w-separator-h\"><\/div><\/div>\r\n\t<div class=\"wpb_text_column \">\r\n\t\t<div class=\"wpb_wrapper\">\r\n\t\t\t<h1><span class=\"ez-toc-section\" id=\"Conclusion\">Conclusion<\/span><\/h1>\n<p>In this post, we have seen:<\/p>\n<ul>\n<li>How to fetch the data from the table using a service node and use it for further processing;<\/li>\n<li>How to update data to the table from the Dialog task using a service node;<\/li>\n<\/ul>\n\r\n\t\t<\/div>\r\n\t<\/div>\r\n<div class=\"w-separator size_small with_line width_default thick_1 style_solid color_border align_center\"><div class=\"w-separator-h\"><\/div><\/div><\/div><\/div><\/div><\/div><\/div><\/section>\n","protected":false},"excerpt":{"rendered":"In this How-To, we will explore a scenario in a Banking Bot, where the account-related data for a customer is stored in a Data Table. We will see how the data can be updated by a request from the user. For details on what Data Tables are and how it is implemented in the Kore.ai...","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[74],"tags":[],"class_list":["post-24061","post","type-post","status-publish","format-standard","hentry","category-how-tos"],"_links":{"self":[{"href":"https:\/\/developer.kore.ai\/v10-1\/wp-json\/wp\/v2\/posts\/24061","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/developer.kore.ai\/v10-1\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/developer.kore.ai\/v10-1\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/developer.kore.ai\/v10-1\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/developer.kore.ai\/v10-1\/wp-json\/wp\/v2\/comments?post=24061"}],"version-history":[{"count":7,"href":"https:\/\/developer.kore.ai\/v10-1\/wp-json\/wp\/v2\/posts\/24061\/revisions"}],"predecessor-version":[{"id":39328,"href":"https:\/\/developer.kore.ai\/v10-1\/wp-json\/wp\/v2\/posts\/24061\/revisions\/39328"}],"wp:attachment":[{"href":"https:\/\/developer.kore.ai\/v10-1\/wp-json\/wp\/v2\/media?parent=24061"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/developer.kore.ai\/v10-1\/wp-json\/wp\/v2\/categories?post=24061"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/developer.kore.ai\/v10-1\/wp-json\/wp\/v2\/tags?post=24061"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}