Save your webform submissions on SharePoint
You can use SharePoint to save and store submissions on nsw.gov.au forms. Saving personal information on SharePoint is safe, secure and sustainable. It also ensures that you and your team are the only ones who can access your form's data.
Before you begin
This integration is the nsw.gov.au standard recommendation. Our Government Technology Platforms quality assurance (QA) and penetration testing teams tested this solution. This ensures NSW Government agencies on nsw.gov.au can use this approach and it is fit for their purposes.
You should consult with your agency's security team with this approach first. Every NSW Government agency has their own unique security requirements. They will assess whether this aligns with your agency's needs or provide you with another solution.
Permissions
Before you can access the appropriate environment in Power Automate you will need to be added into a security group. Please create a Service Desk request at Service Now requesting access to the security group NSWGOV-APP-DCS PTO-ACCESS. Once you are assigned to the security group, contact the Platform team to get access to the Power Automate DCS PTO Non Prod environment.
Connecting your webform to SharePoint through Power Automate
Power Automate is a Microsoft application that allows users to automate workflows. You will use this application to connect your webform to SharePoint. Once complete, SharePoint will store your webform submissions. You and your team will then use SharePoint to access the data.
There are 6 steps to do this:
Create a flow
The Power Automate connection between your webform and SharePoint is called a flow. Every webform you set up for your agency pages on nsw.gov.au will need to have its own flow. In the following steps, we will be creating a flow in the test Power Automate environment named DCS PTO Non Prod.
Follow the steps to create a flow for your webform:
-
Navigate to the Aa-CloudFlow-Template flow via the referenced link. (This flow is found in the DM Drupal to Sharepoint HTTPS solution)
Alternatively, you can navigate to the flow directly by clicking on Solutions in the left hand menu and then clicking on the Drupal to Sharepoint HTTPS solution in the list of Solutions. In the solution the Aa-CloudFlow-Template flow will be present. You will use this flow as a template for your webform. Enter the flow by clicking on the flow.
If you experience issues accessing the workflow, raise a support request through our form.
-
Once you are in the flow click Save As. This will create a copy of the flow.
-
Sign in to all of the available connections until a green tick appears. Then click Continue.
Note: it is best to use a service account when signing in to the connections.
Using a service account means that the connections do not rely on an individual user account. For example, if an individual leaves your agency, the integration may stop working. A service account ensures your workflows are always secure and continuous.
You can get a service account set up through your agency's SharePoint admins.
-
Assign the flow a name.
For best practice, use the name of the page the form will be used on.
- Click Save once done.
- Click My flows on the left-hand sidebar.
- Click on the flow you created in step 4.
-
You should now see the details for the flow. Ensure that the solution is pointed to Drupal to Sharepoint HTTPS.
If you need other people to have access to edit the flow, follow the below steps:
- Click My Flows on the left-hand menu.
- Click on the flow you created.
-
Click Edit on the Co-owners section.
-
Type in the name or email address of the users you want to share the flow to. Select them from the search results that pop-up.
- Click OK on the Before you share… pop-up window.
Connect a flow to a form in the CMS
After creating the flow it needs to be connected to your form in the nsw.gov.au content management system (CMS). Follow the below steps to set this up:
-
Open your flow and click Edit on the top menu bar. (Note: do not click on ‘Edit’ to the right of ‘Details’)
- Disable the New designer view by untoggling the New designer switch on the top-right. Alternatively you can disable the new designer by changing the text at the end of the URL from v3=true to v3=false
-
The flow should now look like the below. This is the flow details page:
-
On the bottom of the page, click Save.
Note: if attempting to save or turn on the flow results in an error, the Sharepoint site referenced in the Create SharePoint Line Item will need to be modified. To fix this error the Create SharePoint Line Item action needs to be configured with the SharePoint site in the Site Address field that will be used for the web form. Step 4 in the Map form fields to SharePoint through SharePoint lists section will need to be carried out.
i.e. Expand the Create SharePoint Line Item action and enter the SharePoint Site in the Site Address text field and select the SharePoint List in the List Name dropdown.
- Once the flow is saved, open When a HTTP request is received by clicking on it.
-
Click the copy icon to the right of the URL inside HTTP POST URL field.
This will copy the URL ready for you to paste into your webform in the CMS.
- Login to the nsw.gov.au CMS and open your webform.
-
Click on Settings then Emails/Handlers.
- Click the + Add handler button.
-
Click Locking remote post (queued) from the list.
- A sidebar on the right to Add Remote post handler will open up.
-
Paste in the URL copied from step 6 on the field Completed URL.
- Click the Advanced tab on the top of the pop-up.
- Ensure the below settings are configured:
- Enable the Remote post handler checkbox is checked.
- Method is set to POST.
- Post type is JSON.
- Include files as Base64 encoded post data checkbox is checked (this will only appear if there are file uploads/attachments fields set up on the form).
- Scroll down and click Save.
Create the webform data schema
The next step is to create the schema of your form data once your form is connected to its own flow.
- Navigate to your form’s flow details page.
-
Ensure your form has a red Terminate action after the Request Body action.
This terminate action will ensure the tests being sent to the flow (in the next steps) will submit while the flow is not fully set up yet.
- Click on Test on the top-right of the page.
-
Ensure the ‘Manually’ option is selected.
If ‘Your flow is disabled right now. You’ll need to enable it before testing.’ message is showing, enable your flow first:
- Click My flows on the left sidebar.
-
Hover over your flow and click on the ellipsis icon that appears to the right of the flow name. Select Turn on from the context menu that appears.
- Go back to the flow details page by clicking Edit. Then click Test on the top-right again.
- Click on the Test button on the bottom of the Test Flow window.
-
This will initiate the flow and give you the below message:
- Navigate to your form on the CMS and click on the Test tab.
- Fill in the form with test data and click Submit. Note: If the form allows the user to upload a file then ensure that the test data in the form includes the file upload.
-
Go back to the flow details page in Power Automate. Expand the Request body action.
There should be code that appears in the Inputs and Outputs sections. This is the JSON schema for the test data you sent from the form in Step 8.
- In the Inputs section, copy the entire text.
- On the top-right of the page, click on Edit.
-
Expand the Step 1: Enter JSON Schema action and click on Parse JSON.
-
Click on the Generate from sample button.
This will open up a pop-up window Insert a sample JSON Payload.
-
Paste in the data inside the section then click Done.
-
For forms with file attachment fields set up, the code (JSON Schema) copied above needs to be updated. The section with the name of the file attachment field needs to include an array string.
Eg, if the file attachment field is named 'upload_field_name':
"upload_field_name": { "type": "string", "items": { "type": "string" } },Change to:
"upload_field_name": { "type": { "array", "string" }, "items": { "type": "string" } },
-
- The webform data schema is now set up based on the form submission.
Map form fields to SharePoint through SharePoint lists
A SharePoint list for the form must be created before the Power Automate flow can be setup. Ensure the list is created before setting up the SharePoint action in the Power Automate flow or the list will not be discoverable within the Create SharePoint Line Item action in Power Automate. Please arrange for someone to create the SharePoint list or arrange to get the appropriate Permissions on the SharePoint site and follow the steps below to create the SharePoint list.
- To do this, you will first need to create a SharePoint list in your SharePoint site.
- Navigate to Microsoft List from your Microsoft 365 apps.
- Click + New List.
- Click Blank List.
- Give your list a name. This should be the form name.
- Click on the Save To dropdown.
- Select the SharePoint site you want your form submissions to be stored in.
- Click Create.
-
Once the SharePoint list has been created, you are ready to create the field items that will be used to map your form to SharePoint. Click + Add column.
-
Create a column item for each field set up on your webform. Ensure the appropriate column type is selected for each field. Refer to the below table as a guide:
Web Form field Column Type Text field Text Textarea Multiple lines of text Checkbox Yes/No (check box) Radios Yes/No (check box) Select / Option buttons Choice Number Number Date/time Date and Time Email Yes/No (checkbox) Signature Image File External Data* Attachment External Data* *Select See all column types then click Next
- Navigate back to the flow details page. Expand the Create SharePoint Line Item action.
- Enter the SharePoint site in the Site Address field. In this step please enter the site address character by character until the auto find brings up the name of the Site Address in the popup list. It may take some time for the popup list to bring up the searched site addresses after a character is typed.
-
Select your newly-created SharePoint List name from the List Name dropdown.
Select your newly-created SharePoint List name from the List Name dropdown.
If the list is not appearing on the dropdown, click Show advanced options then Limit Columns by View > All Items in the field to refresh the view.
The below form field types need to be set up in a specific way to ensure its values are captured in SharePoint.
- Checkboxes
- Select (multi-select dropdown)
- File upload elements (audio, document, file, image, video)
- Signature
If your form includes any of these fields, expand each of the options below for instructions on how to set them up.
-
Navigate to the flow details page and expand the Create SharePoint Line Item action.
-
Click on a checkbox field.
This is set up on your form as a checkbox form element, and on the SharePoint List column as a YES/NO column item.
-
A pop-up window will appear on the right. Click on the Expression tab.
-
In the code below, replace CHECKBOX NAME with the key name of the field in the CMS.
if(equals(body('Parse_JSON')?['CHECKBOX NAME'],'1'),true,false)Eg: in this below example, the key name is ‘nr_test_form_checkboxes’.
So the code will read:
if(equals(body('Parse_JSON')?['nr_test_form_checkboxes'],'1'),true,false) -
Type in the updated code in the fx text field.
Do not paste it in. An error will pop-up if so. The code also should not contain any spaces.
Once done, click OK.
-
Repeat these steps for every checkbox field on your form.
-
Navigate to the flow details page and hover over the arrow above the Create SharePoint Line Item action. An add (+) icon will appear. Click on the icon to Insert a new step.
-
Click Add action from the window that pops-up, then type in Apply to each on the search field.
-
Select Apply to each from the results that appear. This should be under Actions.
-
Click on the Select an output from previous steps field. A pop-up window on the right will appear.
-
On the Dynamic content > Parse JSON section, select the multi-select field.
-
Click on Add an action inside the Apply to each action item.
-
Search for Compose and select it under Actions. You can rename the compose action to give it a unique name by clicking on Rename in the menu opened when you click on the 3 dots on the right hand side of the action box.
-
Click inside the Inputs field and paste in the below code:
{ “value”:”<current_item>” } -
Highlight <current item> inside “” then delete it from the code. So the code looks like:
{ “value”:”” } -
Then, on the pop-up on the right, inside the Dynamic content > Apply to each section, select Current item.
-
The code inside the Inputs field should now look like the below:
-
Expand the Create SharePoint Line Item action and click on the multi-select field.
-
On the pop-up on the right, click Expression, then type in the below code:
outputs(‘compose action name’) -
Replace compose action name with the name of the compose action you created inside the Apply to each action.
Eg, if the Compose action is named “compose”, the code will be:
outputs(‘compose’)-
If there are spaces in the name, the spaces will need to be replaced by underscores (_) in the code. Eg, 'first name' will be 'first_name'.
-
-
Click OK once done.
-
Navigate to the flow details page and expand Check if attachment field contains data action.
-
Click on the Choose a value field, and in the popup under Dynamic content > Parse JSON select the name of the file upload field.
-
Expand the Yes condition, then expand the Add Single File Attachment File or Video action.
-
Clear off both the File Name and File Content field by clicking on the “x” icon on the populated values. You will be replacing these with the column fields you created in your SharePoint list.
- Next, enter the File Name and File Content fields for the file upload:
a) *File name: in the popup under Dynamic content > Parse JSON select the column name for the file name of attachments.
b)For *File Content: in the popup under Expressions enter base64ToBinary in the fx textfield
for the data value of the function in between the parentheses enter the 'data' field by selecting it in the Dynamic content in the popup under the Parse JSON section. The value in the fx field will resemble the following (for the example below _upload_document is the key name of the file upload) :
-
If your form allows submission of multiple attachments, expand the Check if multifile array contains data action.
-
Click on the Choose a value field, and in the popup under Dynamic content > Parse JSON select the name of the multi-file upload field.
-
Expand the Yes condition, then expand the Add Attachments Multi file Control action.
-
In the Select an output from previous steps click the “x” icon on the populated value to clear off the field.
-
Click on the Select an output from previous steps field then select the multi-file upload field under Dynamic content > Parse JSON.Refer to this Guide to Multi file attachments for further information
-
Navigate to the flow details page and expand the Check if Signature Field contains data action.
-
Ensure the action has the following setup:
- Signature
- is not equal to
- null
-
Click on x to the right of signature to clear off the field.
-
Click on the Choose a value field and on the Dynamic content > Parse JSON popup, select the name of the signature field.
-
Open the Split Mine and Base64 action under the Yes condition. Then click on the fx split(…) item inside inputs.
-
A pop-up will open with the Expression tab selected and the fx text field populated with the following code:
split(body('Parse_JSON')?['signature'],',') -
In the code, replace signature with the id of the signature field in your form.
Eg, a signature field with an ID of ‘formsig’ will look like:
split(body('Parse_JSON')?['formsig'],',') -
Once done, click Update.
-
Open the action Add attachment 2 inside the Yes condition.
-
Fill in the details for Site Address (the SharePoint Site) and select the List Name (the SharePoint list for the form) from the dropdown.
- *File Name: enter a file name of the signature you want saves in SharePoint.
- *File Content: can be left as-is.
If your form does not include any one of these fields, click on the horizontal ellipsis icon (to the right of the action) and select Delete for the form field types you do not require.
Set up notifications for webform submissions
After the webform has been set up to connect with SharePoint, you can set up notifications for every successful submission on your webform as well as notifications of SharePoint list item creation failures.
You can set up notifications to be sent to you on both Email and Microsoft Teams.
On the flow details page, expand the Send an email (V2) action.
Clear off the *To field by clicking on the “x” icon for all email addresses listed on the field.
Type in the email address/es of the people who will be receiving notifications of the webform submissions. Select their name from the pop-up that appears.
*Subject: Enter the subject of the email. Eg: Aboriginal Feedback form submission.
*Body: Enter the body copy of the email. Eg: A submission has been received on the Aboriginal Feedback form.
More options can be configured by selecting Show advanced options.
The email notification for SharePoint list failures can be configured as above in the action Send an email (V2) 2 action as shown below
On the flow details page, expand the Apply to each action on the top of 'Send an email (V2)' action.
Then, expand Post a message in a chat or channel 2 action.
*Post as: either the User (the action creator) or the automated Flow Bot.
*Post in: either in a Teams Channel, Group chat, or a private Chat with Flow bot.
- If selecting Channel, you will need to add in the Team ID and the Channel ID in the respective fields.
*Message: Enter the message that will be posted to Teams when a submission is received. Eg, A submission has been received on the Aboriginal Feedback form.
Then, on the flow details page, expand the Initialize Recipients Array action.
Inside Value, add in the email addresses of anyone who will be receiving the notification on Microsoft Teams. Each email address should be inside “” and separated by a comma (,). Every entry needs to be nested inside “[ ]”
Test the webform for submissions saving to SharePoint
You are now ready to test whether your webform will save submissions on SharePoint. Follow the below steps to test out your webform:
-
Delete the Terminate action.
Select the “…” ellipsis to the right of the action, then select Delete.
- Click Save on the top-right of the page to save the flow.
- Click Test on the top-right of the page to initiate the test.
-
Select Manually in the Test Flow prompt, then click the Test button.
- Navigate to your webform on the CMS and click on the Test tab.
- Fill out the form, then click Submit.
- The test submission will trigger the flow in Power Automate. Observe the status of the flow.
- Once the test has been completed, navigate to your SharePoint site list and check the webform submission.
You can check the outcome of any test you perform on the flow by clicking on My Flows on the left-hand menu. Click the vertical ellipsis icon to the right of the flow then click Details.
The 28-day run history section will show all tests run within the last 28 days. Each test will have details on when it was run, how long the test ran for and the outcome of the test.
Once the created flow is completed and has passed testing the flow can be promoted to the DCS PTO production environment. To promote the flow to the production environment please contact the platform ops team via email dcuplatformdevops@customerservice.nsw.gov.au with the name of the flow that you created to be promoted.
Need any more help?
If you have any questions, or require assistance with anything mentioned in this article, submit a request via the webform.