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

VbPowerPlatform 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.
205 questions
Microsoft Copilot
Microsoft Copilot
Microsoft terminology for a universal copilot interface.
503 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.
564 questions
0 comments No comments
{count} votes

3 answers

Sort by: Most helpful
  1. Nivedipa-MSFT 3,091 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

  2. Vivek Bhakta MSFT 100 Reputation points Microsoft Vendor
    2025-01-21T10:50:15.1533333+00:00

    Please ignore previous comment.

    0 comments No comments

  3. Vivek Bhakta MSFT 100 Reputation points Microsoft Vendor
    2025-01-21T10:56:45.9833333+00:00

    Collect and Store User Responses through Power Automate and Power Apps
    __
    Using Power Automate and Power Apps:

    1. Create a Power Automate Flow:
      • Trigger: Start with a trigger that initiates the flow when a new response is submitted in your chatbot.
      • Initialize Variables: Use the "Initialize variable" action to create an array variable that will store the user's responses.
      • Append to Array Variable: As each response is collected, use the "Append to array variable" action to add the response to the array.
      • Update SharePoint List: At the end of the conversation, use the "Create item" or "Update item" action to save the collected responses to your SharePoint list.
    2. Design a Power App:
      • User Interface: Create a user-friendly interface in Power Apps where users can interact with the chatbot and submit their responses.
      • Data Collection: Use Power Apps to collect user responses and store them in a collection.
      • Trigger Flow: At the end of the conversation, trigger the Power Automate flow to process and save the responses.

    Steps to Implement:

    1. Set Up Power Automate Flow:
      • Go to Power Automate and create a new flow.
      • Choose a trigger, such as "When a new response is submitted" from Microsoft Forms or any other relevant trigger.
      • Add actions to initialize and append to the array variable.
      • Use the "Create item" action to save the responses to the SharePoint list.
    2. Create Power App:
      • Open Power Apps and create a new app.
      • Design the app to include input fields for each question.
      • Use collections to store user responses.
      • Add a button to trigger the Power Automate flow at the end of the conversation.

    By using Power Automate and Power Apps, you can create a no-code solution to collect and store user responses dynamically, ensuring a seamless experience for both the users and administrators.

    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".


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.