Limit number of Responses in Microsoft Form

Within Microsoft Forms it is possible to close the form for new responses. In this article I will show you how to update this setting based on the number of responses via a Power Automate flow.

Inspiration

This question from Armin2:

Is it also possible that the link expires after the first use and can only be used once, so to speak?

Power Users Community thread: create a Link to a form which expires after the first use.

limitnumberofresponsesforms

Options for Responses

In the interface you have a couple of options for responses. You can set the End date, which can lock the form down after a certain date. This is also the option which I suggested to Armin2 in the Power Users Community thread.

But in this blog I also looked into the Accept responses option. The benefit of that option is that it also includes a Message to recipients field which you can use to present a message to the end user why it has been closed down, which is probably a bit more user friendly.

optionsforresponses

Forms API

Like demonstrated in the Get Microsoft Forms responses submitted today blog you can interact with your Form via the Forms API and a Send an HTTP request to SharePoint action in a Power Automate cloud flow.

In this example I am going to use the API to retrieve the responses of the form and check the total number of responses in a condition. You can do this by using a length function to check the number of items within the returned value property.

In this example want the form to be closed down after 5 responses.

I am also going to use a PATCH request to set the FormClosed boolean property to true and provide a text in the FormClosedMessage property.

Flow Setup

For this sample I am using personal Microsoft Form.

limitnumberofresponsesforms_flow

1. Add a When a new response is submitted action.

whenanewresponseissubmitted

a. Select your form from the dropdown

2. Add a Get response details action.

getresponsedetails

a. Select your form from the dropdown
b. Provide a Response Id, use the Response Id field from the Dynamic Content.

3. Add a Get user profile (V2) action.

getuserprofile

a. Provide a UPN, in this case the UPN of the user who created the Microsoft Form.

4. Add a Send an HTTP request to SharePoint action.

The URI uses the tenant id (which in my case is a parameter), the id of the user who created the form and the form id (which is retrieved from the dropdown in the first action).

sendanhttprequesttosharepoint

a. Use the https://forms.office.com as the SiteAddress.
b. Use the GET method
c. Use the URI from the code snippet below

d. Use the Headers from the code snippet below

5. Add a Condition action.

condition_length

a. Use the expression below for the condition

6. Add a second Send an HTTP request to SharePoint action.

The URI uses the tenant id (which in my case is a parameter), the id of the user who created the form and the form id (which is retrieved from the dropdown in the first action).

patch_formclosed

a. Use the https://forms.office.com as the SiteAddress.
b. Use the PATCH method
c. Use the URI from the code snippet below

d. Use the Headers from the code snippet below

e. Use the Body from the code snippet below

That should be it for the setup.

Happy testing!

You may also like...

9 Responses

  1. Toby Teng says:

    Hi Dennis, Thank you so much for this. May I know how can I get the tenant id in step four please?

  2. Dennis says:

    Hi Toby,

    You can for example find in Entra Id. But there is also a website for that:
    https://www.whatismytenantid.com/

  3. mohamed says:

    Hi Dennis.
    I get an error on the condition level
    ‘length(outputs(‘Send_an_HTTP_request_to_SharePoint’)?[‘body’][‘value’])’ cannot be evaluated because property ‘value’ doesn’t exist,

  4. Dennis says:

    Hi Mohamed,

    What outputs is the Send an HTTP request returning. Are you seeing by any chance a ‘d’ property?

    Did you use the same verbose Headers in the Send an HTTP request.
    {
    "Accept": "application/json;odata=verbose",
    "Content-Type": "application/json;odata=verbose"
    }

  5. Mohamed says:

    Thanks for your help! Your workaround did the trick perfectly once I adjusted the verbosity settings. I made a few tweaks to fit my needs better, like changing the condition to a greater-than comparison and adding an automatic email to the Responder with the form’s context.

    Just a heads up, though—the form still records responses and confirms to users, which might be misleading. So, I added the email notification for clarity.

    Thanks again for your support

  6. Mohamed says:

    I wonder if there is a way to change the expiration date on the form once the desired number of responses reaches.

  7. Dennis says:

    This setup should close the form and you should not be able to respond anymore, that is what is done in step 6 of the flow with the PATCH request. So, this does not work for you?

  8. Hannah says:

    Hiya, does this only work for a single user using the form? or will this work for multiple submitters?

  9. Dennis says:

    Hi Hannah,

    This applies to all submitters trying to submit a new response after a certain amount of total responses. In this example it closes after a total of 5 responses.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.