Thursday, September 30, 2021

PowerApps: Pen Input Control

 Hello Friends,

Welcome back with another post on PowerApps. As we have nowadays, lots of delivery person ask to sign on their mobile app during delivery of product. Have you ever thought that how it could get done and will it be possible in PowerApps?

Yes, it is possible in PowerApps and is quite simple. Let's see-

  1. For this, we will develop-
    1. PowerApps: Here, we will use PenInput control to allow user to draw his/her signature.
    2. Power Automate: This flow will be used to pick data from PowerApps and save in SharePoint library.
  2. Open the SharePoint site and click on App launcher icon (9 dots at top left corner). Here you will find the PowerApps site link. Click on it.
  3. It will open the PowerApps maker site. Here click on "+ Create" or "+ New App" and select Canvas app.
  4. Now click on Insert >> Input >> Pen input.


  5. Now add button and set display text as "Submit".
  6. Now whatever, we will draw on this Pen Input Canvas, we will save it in a variable. But before saving, we will extract the actual content of file because, the content itself in the form of base64 with prefix and suffix added to it. The same kind of extraction we have done in one of our earlier post.
    1. PowerApps: Upload File To SharePoint
  7. We will use below function for OnSelect property of button.
  8. UpdateContext(
        {
            vrPenInputData: JSON(
                PenInput1.Image,
                JSONFormat.IncludeBinaryData
            )
        }
    );
    UpdateContext(
        {
            vrBase64Value: Mid(
                vrPenInputData,
                Find(
                    ",",
                    vrPenInputData
                ) + 1,
                Len(
                    Mid(
                        vrPenInputData,
                        Find(
                            ",",
                            vrPenInputData
                        ) + 1
                    )
                ) - 1
            )
        }
    );
    

  9. Here we have partially completed the first part. The remaining part of the first part is to send this data to Power Automate to save in SharePoint Library.
  10. Therefore, first we have to create a Power Automate.
  11. For this, there are 2 options-
    1. Click on Action >> Power Automate >> + Create a new flow.
    2. Open the Power Automate site from the App Launcher >> Power Automate. Here you may click on + Create to create flow. Select the Instant Cloud Flow and then choose PowerApps.

  12. Now click on + New action and add an action names "Create file (SharePoint)".

  13. Select the Site address, folder name.
  14. Set File name as utcNow() with added extension of file as ".jpg".
  15. For file content, click on Ask In PowerApps from Dynamic Content window. It will create a dynamic variable that will be used to ask the file content from PowerApps.
  16. Save the flow. Now remove the file content variable from input box and click on Expression box. Use base64tobinary() function and pass this variable to this function and click on OK.
  17. Save the flow and come back to PowerApps.
  18. Now, first of copy the code of OnSelect property of button to a notepad. Then click on Action >> Power Automate. It will load all the PowerApps related flows. You will find the recently created flow here. Click on it to get added in OnSelect property.

  19. a
  20. The moment it will be added in OnSelect property, the rest code will get wiped. That's why, we have copied that code in notepad. Now copy the code from notepad and paste it back before the recently added PowerAutomate Code.
  21. Now, pass the variable vrBase64Value to this flow.

  22. That's all. Now save the PowerApps and play it.


  23. This way, we can achieve this functionality.
With this, I am concluding this post.
Happy Coding !!!
Will see you again with some new topics.

Stay Safe !
Stay Healthy !

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.