Showing posts with label Power apps tips. Show all posts
Showing posts with label Power apps tips. Show all posts

February 18, 2021

How to covert out of the box (OOTB) Power Apps Dropdown to Checkboxes?

Overview:

We implemented several Power Apps forms (customized SharePoint Forms) for a consulting firm based out of Alpharetta, Georgia, United States. When we customize our SharePoint form having a choice column, Power Apps represent the choices as a dropdown. For one of the forms we implemented, the requirement was to display checkboxes instead of a dropdown list for a choice column. So, how can we achieve this requirement? Let’s get started!

  1. Open your customized SharePoint Power Apps form.
  2. We need to add Checkboxes in the same data card as the dropdown. To add a checkbox, go to the insert menu and add a checkbox. Add checkboxes based on the # of choice value from the dropdown.


  3. Now, we need to create one group for all checkboxes. In this group add default property using the below code.
     Self.Text in DataCardValue2.SelectedItems.Value  


  4.  For each Checkbox, we need to execute the below piece of code on both "OnCheck" and "OnUncheck" events. Add the following code to the "OnCheck" and "OnUncheck" events. The code is same for both the events for all the checkboxes.
     ClearCollect(ddtocb,  
     If(Checkbox1.Value,Checkbox1.Text),  
     If(Checkbox1_1.Value,Checkbox1_1.Text),  
     If(Checkbox1_2.Value,Checkbox1_2.Text),  
     If(Checkbox1_3.Value,Checkbox1_3.Text),  
     If(Checkbox1_4.Value,Checkbox1_4.Text),  
     If(Checkbox1_5.Value,Checkbox1_5.Text),  
     If(Checkbox1_6.Value,Checkbox1_6.Text),  
     If(Checkbox1_7.Value,Checkbox1_7.Text),  
     If(Checkbox1_8.Value,Checkbox1_8.Text),  
     If(Checkbox1_9.Value,Checkbox1_9.Text),  
     If(Checkbox1_10.Value,Checkbox1_10.Text),  
     If(Checkbox1_11.Value,Checkbox1_11.Text)  
     );  
     ClearCollect(ddtocb,Filter(ddtocb,!IsBlank(Value)))  
    


  5. Now, select dropdown and open the DefaultSelectedItems property. Pass collection created in the above step using the following code snippet.
     If( IsEmpty(ddtocb),Parent.Default,ddtocb)  
    


  6.  Select final Data Card and change Update property using the following code snippet.
     If( IsEmpty(ddtocb),ThisItem.'<Field Name>',DataCardValue2.SelectedItems)  


  7. At last, change the dropdown’s visible property to make it false.

Conclusion:

This is how we can convert our dropdowns to checkboxes.

If you have any questions you can reach out to our SharePoint Consulting team here.

January 12, 2021

Allow users to upload only specific extension files in Power Apps Attachment control

Introduction:

In this blog, we will learn how to allow users to upload only specific extension files in Power Apps Form Attachment control. The example here we have carried in this blog is to allow users to upload only the ".pdf" extension files.

Resolution:

Below are the steps we are going to work on here!

1.     Set restriction on uploading other extension files in Attachment control and notify the user when they upload any extension file other than ".pdf".

2.     Restrict the user from saving until resolving file errors.

Step 1: Set restriction on uploading other extension files in Attachment control

Place the below code at OnAddFile property of the Attachment control:

 If(  
   CountRows(  
     Filter(  
       RenameColumns(  
         DataCardValue4.Attachments,  
         "Name",  
         "NewName"  
       ),  
       Last(  
         Split(  
           NewName,  
           "."  
         )  
       ).Result <> "pdf"  
     )  
   ) > 0,  
   Notify(  
     "Only PDF files can be attached",  
     NotificationType.Error  
   );  
   ,  
   SubmitForm(Form1);  
   ResetForm(Form1);  
   EditForm(Form1);  
   )  

After placing this, check by adding a different extension file in the attachment control. You will be able to see this type of error at the top of the app.


Now as we have set the restriction message, let’s restrict the user from saving the form until all the attachments in the control are ".pdf".

Step2: Restrict user from saving until resolving file errors

Place the below code in the OnSelect property of the save button or in the OnSave property of SharePointIntegration:

  If(  
   CountRows(  
     Filter(  
       RenameColumns(  
         DataCardValue4.Attachments,  
         "Name",  
         "NewName"  
       ),  
       Last(  
         Split(  
           NewName,  
           "."  
         )  
       ).Result <> "pdf"  
     )  
   ) > 0,  
   Notify(  
     "Only PDF files can be attached",  
     NotificationType.Error  
   );  
   ,  
   SubmitForm(Form1);  
   ResetForm(Form1);  
   EditForm(Form1);  
   )  

Now add a different file extension in the control and click on save. It will show the below error and won’t let the user save the item.

Conclusion

This is how we can restrict users to upload only ".pdf" extension files in the Power Apps - Form Attachment Control.

If you have any questions you can reach out our SharePoint Consulting team here.