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...

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.