Title: Create, Validate and Read Custom Form for Attended Automation in Power Automate Desktop
Problem Statement:
During automation, there arises a need to capture information from the user as part of Attended Automation. For this purpose, we could make use of the in-built Custom Form action of Power Automate Desktop (PAD) to ask the user for the required details and then transfer these details to other systems or applications.
- Build a Form like the one shown by dragging each of the controls from the Form Designer.
- Drag the 'Display custom form' action onto the Flow Designer to build the Custom Form
-
- Double click the action and then go to 'Custom form designer'
-
- Drag the desired controls from the left onto the Form structure on the right. You can build a Form as per your requirement. In doing so, I have built a Form such as this by using every single available control element. Refer the mapping of controls.
Use the ID box (on the right hand side) for each element and give their names as per 'control naming convention' as best practices. On doing so, the Form structure would look like the below.
And what you write in the 'Label' section will show up next to that control as a Label.
- How to do Validation for mandatory fields if they are left blank by user
- In the Specifications on the right hand side, tick the box that says 'Required' and in the 'Error Message' box give a user-friendly error message.
- I have done the same for the Age box which is a 'Number Input' control, marked the field as 'Required' and provided a meaningful message.
-
- This is how the custom error message shows up if left blank or if anything other than a number is entered in the Number Input box. The red asterisk mark next to the Label 'Full Name' indicates to the user that the field is required.
-
- Please note that since this is a Number Input field, it will also allow decimals. If you do not want to allow decimals then use a 'Text input' element and apply regex on it (shown in next point).
- Validation using regex pattern for fields like name, email address, phone numbers, etc.
- For the txtName element I have marked it as 'Required', given an error message and a Regular Expression
- I have used a regex pattern for a first name followed by 1 space followed by 1 optional alphabet followed by 1 space followed by last name and also the first and last name would be anywhere between 2 and 30 characters long. ^[a-zA-Z]{2,30} ?[a-zA-Z]\.? [a-zA-Z]{2,30}$.
The output after running it in real time would be as below. It won't accept if the first name is not at least 2
characters long. This is just an example regex and the intent is to show how to use a regex for validation of fields like names, email addresses or phone numbers.
- Other design considerations used on the Form
- This is a Text Block control and the blue color it gets is from the Color property.
-
- Here is another example of how the message looks after changing the Color property.
-
- The line that shows up above the Text Block is the 'Separator' property. The way it works is: A separator line automatically appears to the top of the control element which has this property ticked.
-
- The 'Choice Set Input' element (or a listbox) should be given as a combination of Title and its Value.
-
- The text added in the 'Title' section shows up on listbox when the Form is run, and the text in the 'Value' is the one that will be saved when a user selects that 'Title'
- For the 'Toggle Input' (or a checkbox), I have kept the Label as blank and used the Title property instead as it looked good on the Output Form. Try it out and see. Also, the 'Value when on' and the 'Value when off' determines what value is saved when the Form is finally submitted depending on whether the checkbox is checked or unchecked by the user.
-
-
You can also give a minimum and maximum value for a Date Field and an error message accordingly.
Click the 'i' information button to read about the Regional Format settings. Currently they appears as
-
textboxes. Hopefully, Microsoft changes these to DatePicker and Time controls in future releases.
Output after running the Form: The year entered is 2024.
- The Ok and the Cancel buttons are one and the same ie; they both are the 'Submit' element with the only difference that the Cancel button has the below property ticked. The Ok button will send the values back to your Flow and the Cancel button won't. Refer the 'i' Information icon shown next to the checkbox.
- The last button 'More Help' is the 'Open URL' element with properties as below which will open the url specified when the button is clicked.
- How to read values from these controls when the Form is submitted
- This is done in a very simple way. On submitting the Form, the data entered by the user is stored into the CustomFormData custom object variable. You simply access its value via the following notation: %CustomFormData['ElementID']% where ElementID is the one you supplied in the 'ID' box while designing the form as per their 'control naming convention'.
- Output stored after submitting the Form:
- Be noted that the values won't be saved if the user presses the Cancel button as that is how we have configured its properties.
- I have attached a Desktop Flow that generates the above Form and also writes the values to a blank Excel file.
- You will see that the formatting of fields such as Date or Time would be different in the Excel than the one entered by the user in the Form. Since that is not the intention of this technical article, things such as those are not handled. The formatting can be changed once you capture the information submitted by the user and before writing it to the Excel (or to any other external application).
- This Flow was built in PAD version 2.33.
Good Luck and Happy Automation!