web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :

Save Power Apps SharePoint offline data including Attachments without a Flow

WarrenBelz Profile Picture WarrenBelz 155,315 Most Valuable Professional
Have you wanted to save offline data in SharePoint, but also needed to include attachments. Here is a way to save, retreive and upload this data using only Power Apps.

Firstly you need a normal Edit Form (classic example here) with an attachment control (example named acAttachments). Data is entered as usual - this process addresses new records only

Now you need a Gallery (galAttachments - which you can hide) - with the Items property
acAttachments.Attachments

In the gallery are two controls - a Text Label lblAttachName with the Text property
ThisItem.Name

and an Image Control imgAttachContent with the Image property
ThisItem.Value

The Image control is needed to resolve the attachment content to the actual file content rather than the format an attachment control uses to reference them.

When you are saving the offline form, it is to a collection - example below colOffline. Add your other fields as required. This example first tests for a connection and submits the form if one exists - you can call the local offline file whatever you want
If(
   Connection.Connected,
   SubmitForm(YourFormName),
   Collect(
      colOffline,
      {
         YourField1: YourContro11Output,
         YourField2: YourContro12Output,
         . . . . . .
         Attachments: 
         Table(
            ForAll(
               galAttachments.AllItems As _Files,
               {
                  DisplayName: _Files.lblAttachName.Text,
                  AbsoluteUri: Blank(),
                  Id: _Files.imgAttachContent.Image,
                  Value: _Files.imgAttachContent.Image
               }
            )
         )
      }
   );
   SaveData(
      colOffline,
      "YourListNameOffline"
   );
   Notify(
      "You are offline - ensure that this data is synchronised with SharePoint when back online",
      NotificationType.Warning,
      5000
   )
)


Now when you need to upload all of the offline records to your SharePont list when back online - at App OnStart
LoadData(
   colOffline,
   "YourListNameOffline"
);

Then to upload the saved files
If(
   !IsError(
      Patch(
         YourSPListName,
         ForAll(
            colOffline As _Data,
            {
               YourField1: _Data.YourField1,
               YourField2: _Data.YourField2,
               . . . . . . .
               Attachments: 
               Table(
                  ForAll(
                     _Data.Attachments As _Files,
                     {
                        DisplayName: _Files.DisplayName,
                        AbsoluteUri: Blank(),
                        Id: _Files.Id,
                        Value: _Files.Value
                     }
                  )
               )
            }
         )
      )
   ),
   ClearData("YourListNameOffline");
   Clear(colOffline);
   Notify(
        "Offline data synchronised",
        NotificationType.Success,
        5000
    ),
    Notify(
        "Offline data synchronisation failed",
        NotificationType.Error,
        5000
    )
)

You should find all the offline records complete with any attachments now in your SharePoint list.

It is also good to have a label on the screen with the Text
CountRows(colOffline) & " offline file/s present - ensure uploaded to SharePoint"

and the Visible
CountRows(colOffline)> 0 && Connection.Connected

You could also have the upload button having the same Visible

Comments