How to create a list/array out of users' responses during conversation in Copilot Studio?

Vaibhavi Shah 0 Reputation points
2025-01-08T05:49:31.41+00:00

Hi All!

 

Power Platform newbie here, trying to work on a requirement:

 

I am working on a Q&A chatbot in Copilot Studio that dynamically gets questions from Sharepoint list. Basically, in the beginning of conversation, user will select one topic and based on the selected topic, questions will be presented to user one by one. (I have one Sharepoint List where I have listed topic-wise questions). I could get these questions dynamically in Copilot.

 

Now, I want to do this:

  1.  Confirm user inputs for each questions at the end of conversation. For which, I want to create an array-like functionality that stores all user inputs.
  2.  Send these answers back to Sharepoint List. i.e. need to trigger a flow from Copilot that saves these data in List.

 

How can I implement this? I tried creating variables that stores user's answers but it is overlapping and at the end, it just shows me the last record. (I have used patch(), I don't know any other way) 

 

Please someone guide me, how can I save these user's answers to all the questions and save it back to Sharepoint list? 

 

Any guidance or help will be much appreciated!:)

Microsoft Copilot for Microsoft 365 Development
Microsoft Copilot for Microsoft 365 Development
Microsoft Copilot for Microsoft 365: Microsoft 365 Copilot refers collectively to Copilot experiences within Microsoft 365 applications.Development: The process of researching, productizing, and refining new or existing technologies.
190 questions
Microsoft Copilot
Microsoft Copilot
Microsoft terminology for a universal copilot interface.
459 questions
Microsoft Power Platform Training
Microsoft Power Platform Training
Microsoft Power Platform: An integrated set of Microsoft business intelligence services.Training: Instruction to develop new skills.
531 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Nivedipa-MSFT 3,061 Reputation points Microsoft Vendor
    2025-01-08T07:56:21.99+00:00

    @Vaibhavi Shah - Thank you for bringing this issue to our attention.
    To achieve your requirement of confirming user inputs for each question and saving these answers back to a SharePoint list, you can follow the steps below:

    Step 1: Create an Array to Store User Inputs

    You need to create an array to store the user's answers dynamically. Here’s an example of how you can do it in Copilot Studio:

    // Initialize an array to store user inputs

    let userAnswers = [];

    // Function to add user input to the array

    function addUserAnswer(question, answer) {

        userAnswers.push({ question: question, answer: answer });

    }

    Step 2: Capture User Inputs

    As you collect user inputs in your conversation, you can add these inputs to the userAnswers array using the function defined above:

    // Example function to capture user input for a qu``estion

    function`` captureUserInput(question) {

        ``// Assume getUserInput() is a function that gets the user input

        ``let userInput = getUserInput(question);

        addUserAnswer``(question, userInput);

    }

    // Call this function each time you get user input`` for a question

    captureUserInput``("What is your name?");

    captureUserInput``("What is your age?");

    Step 3: Trigger a Flow to Save Data in SharePoint List

    Once you have collected all the user inputs, you can trigger a Power Automate flow to save the data back to a SharePoint list. First, create a Power Automate flow that accepts an array of answers and saves them to the SharePoint list.

    Step 4: Connect the Flow with Copilot Studio

    You need to trigger this flow from your Copilot Studio actions. Here’s an example of how to do it:

    Create a Power Automate Flow:

    Create a new flow in Power Automate that starts with a manual trigger.

      Add an action to parse the incoming data (JSON) and save each item to the SharePoint list.
      
         Save the Flow.
         
         **Trigger the Flow from Copilot Studio:**
         
            Use the HTTP request action to trigger the Power Automate flow with the collected user inputs.
            
    

    // Example HTTP request to trigger Power Automate ``flow

    const`` flowUrl = "https://<your-flow-url>";

    const`` response = await fetch(flowUrl, {

        method: ``'POST',

        headers: ``{

            ``'Content-Type': 'application/json'

        ``},

        body: JSON.stringify``(userAnswers)

    }``);

    Step 5: Ensure Data is Saved to SharePoint

    Make sure your Power Automate flow correctly parses the incoming data and adds each item to the SharePoint list.

    By following these steps, you can collect user inputs throughout the conversation, store them in an array, and then save these inputs back to the SharePoint list using a Power Automate flow.

    Doc References:

    Frequently asked questions for Microsoft 365 Copilot extensibility - Frequently asked questions for Microsoft 365 Copilot extensibility

    Extend with actions using Microsoft Copilot Studio - Related information

    Frequently asked questions for Microsoft 365 Copilot extensibility - General questions

    1 person found this answer helpful.
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.