You are currently viewing Adding a Canvas App to a Model Driven App-Part 3 Completing Canvas App and Uploading files to SharePoint vs Dataverse

Adding a Canvas App to a Model Driven App-Part 3 Completing Canvas App and Uploading files to SharePoint vs Dataverse

  • Post author:
  • Post category:Uncategorized
  • Post comments:0 Comments

2/20/2023


The Why

This section will guide you through completing the canvas app, enabling it to save documents to the SharePoint Document library vs saving it to Dataverse, and marking the file as complete in Dataverse.

The How

This guide is built as thought the SharePoint Document Library Integration has been configured and is live. Use the following guides to properly configure the integration.

App Design

  1. Add a save icon to the gallery.
  2. Set the template fill to a IF statement based off of the Completed column.
    If(
        Text(ThisItem.Completed) = "No",
        RGBA(
            0,
            0,
            0,
            0
        ),
        LightGreen
    )
  3. Set the attachment control to hide if the attachment is marked as completed.
    If(
        Text(ThisItem.Completed) = "No",
        true
    )
  4. To prevent users from uploading files when nothing is attached, we can hide the save icon until a file is attached.
  5. Select the save icon, set the visible to hidden until an attachment is added
!IsBlank(First(attachmentControlUS.Attachments).Value)

Upload form with Automate Flow

  1. From the left hand pane create a new flow
  2. Delete the Power Apps trigger and replace it with the Power Apps V2 trigger. Add the following items to the trigger
    1. Document Type
    2. Document Name
    3. Request ID
    4. Document ID
    5. File Content
  3. Add a SharePoint Create a file action
    1. The SharePoint site will be the one configured for the particular table
    2. The Folder Path will match the folder path setup during the custom SharePoint link
    3. The File Name is a concatenation of the Document type and the file name
    4. The File Content will be the file content from the trigger
  4. Add a SharePoint Get file properties action. This action is used to get the SharePoint URL and other attributes
    1. The Site address is the same as above
    2. The Library is the same as above
    3. The Id is the ID from the above action
  5. Add a Dataverse Update a row action
    1. The Table name will be the documents table
    2. The Row ID will be the Document ID from the trigger
    3. The Completed will be marked as “yes”
    4. the SharePoint Link will be gathered from the above action.

App code

Back in the canvas app we will now finish the app and the code to kick off the flow.

  1. Add a new screen to the app called Complete Screen
  2. On the gallery save icon add the following code
    Select(Parent);
    UploadfiletoSharePointandmarkascompletedinDataverse.Run(
        ThisItem.'Document Type',
        First(attachmentControlUS.Attachments).Name,
        ThisItem.'Customer Requests'.'Customer Requests',
        ThisItem.'Purchase Request Documents',
        {
            contentBytes: First(attachmentControlUS.Attachments).Value,
            name: First(attachmentControlUS.Attachments).Name
        }
    );
    Navigate('Complete Screen')
  3. The canvas app is now ready to test.

Testing the App

  1. From the MDA create a new record. The Canvas app along with the documentation location will be displayed/created.
  2. Upload a file using the document control and verify that the file uploads and is marked as completed.
  3. The app's core functionality and flow have been completed. Further enhancements can now be made to the UI to improve the canvas app.

Leave a Reply