Database Search - How to get data from the table and let the user know his answer

@Doggy-Wild_and_Free

Here is the right sequence to perform this action

Step1: perform the search operation in the bot flow to return the the results in the format @Subhrajit_Gupta has shared here

Step 2: Make sure you store the DB response in an object. here I’m storing it in <dbResopnseObject>

Step 3: use the function node after the DB node and call a function

Step 4: Log the data using the format shared below

return new Promise(resolve => {
        let dbResponse = data.variables.dbResponseObject;
        ymLib.logger.log(dbResponse,"Sample-DB-Search");
        resolve();
    });   

Step 5: In the functions page, open up the logs by clicking on the icons on the right
This works like any other log. Click inside the logs and search for <Sample-DB-Search>


This is the DB response for the search action performed. You can now parse and use this data inside your functions

Step 6: Parse this data in the function. In this example, I’m fetching a sample mobile number that’s part of the user details table. Make sure to RESOLVE the data

return new Promise(resolve => {
        let dbResponse = data.variables.dbResponseObject;
        ymLib.logger.log(dbResponse,"Sample-DB-Search");

        let user_phone = dbResponse.records[0].userphone;
        ymLib.logger.log(user_phone,"Sample-phone");
        resolve(user_phone);
    });

Step 7: Back in the bot flow, store the returned value inside a variable of string datatype.
In this example, I’m storing the response in a variable called phoneNo in the bot flow and then printing it inside a text node.

Screenshot 2022-12-12 at 11.25.49 AM