}

PowerApps: Save Your Data Offline

21/11/2019

[:en]Last year, I created an inspection app for users to take pictures of equipment that will be rented out by their clients. Since this company works with oil companies, the app users find themselves in areas without reception. They would like to be able to save the data offline and upload later when they have better service. In addition, some users have limited data plans and want to only upload when they are connected to WiFi.

So in comes PowerApps offline capability.

To set this up, we will need 2 buttons. One to save the data offline and the other to save online. If the user selects upload, a flow will kick in and upload the images to SharePoint. (That is another lengthy post, addressing the complexities of uploading images to SharePoint with PowerApps. John Liu addresses the topic very thoroughly in his blog.)

When the user selects save offline, the data gets stored in a collection in a local file on the phone. Then the user can safely exit the app, without loosing the data. When they open the app again, the app will check if the local file is empty or not. If it is not empty, the data will display in the app for the user to upload.

Note of caution, you want to limit the amount of data the users can save offline as the size of the local file is limited. It varies based on the type of phone you are using.

Ok, lets get into the rules and formulas that you need to make this happen.

First off, we have a status indicator to let us know if we are connected to the internet or not. Its not really need in this app scenario but its a feature you can have so why not.

We have two controls that can display the connection status of the app. A toggle control and a label control. I am using the toggle control to check the connection and then the label control checks that outcome from the toggle control to display the appropriate text.

PowerApps now has a property to check if the app is connected: Connection.Connected

If this returns as true, the toggle will display a green color otherwise it will display as red.



The text control, check if the toggle control value is true or false and displays the appropriate text accordingly.



Now lets set up our button controls.

The upload button is using a flow to upload the images to SharePoint using John Liu's hack to upload images to SharePoint. Read more here

The save offline button, creates a collection that I called Local_Photos and saves the data to the local file called Saved_LocalPhotos. Then, I clear the collection for All Photos, that is where the images are stored when the user takes or attaches images to the app. Next I am navigating to a new screen called local photos where the user can choose to add more photos, close the app or upload the photos.

Formula:
Collect(Local_Photos, ShowColumns(Gallery5.AllItems,"Image","Filename","Description_temp","Latitude_temp","Longitude_temp","Site_temp")); SaveData(Local_Photos, "Saved_LocalPhotos"); Clear(AllPhotos); Navigate(LocalPhotos, ScreenTransition.None)

Next, we need to create an OnStart formula, that will load the local collection and check if there is any data in it. If yes, the data will load and display in the app and take them to the Local Photos screen for them to upload their photos. If there is no local data, it will take them to the main input screen.

Select the App, from the left navigation and then select the OnStart property for the app.



Formula:
LoadData(Local_Photos2, "Saved_LocalPhotos", true); If(CountRows(Local_Photos2) > 0,Navigate(LocalPhotos, ScreenTransition.None), Navigate(InputForm1, ScreenTransition.None))

Another item, whatever mechanism you are using to upload your photos, you will need to clear the local collection once the data is uploaded to SharePoint. Once the data is uploaded, we don't need to store it locally anymore. So we are clearing the Local_Photos collection and then saving the empty collection to the local file.

Formula:
Clear(Local_Photos);SaveData(Local_Photos, "Saved_LocalPhotos")

And that is using the offline PowerApps capability![:]

Written by Malka Pesach

In honor of Women’s History Month we are going to showcase some of our incredible female instructors through a series of blogs! Tell us a little bit about yourself: I am a hardworking mom of 2 beautiful girls who likes a good challenge and a glass of wine every now and then. Professionally, I started in the medical field as a phlebotomist for a cardiologist with hopes of pursuing a career in the medical field. But man plans and god laughs. After leaving my job at the cardiologist office, I ended taking a job at Shell to help with their SharePoint environment as a temporary job. I stayed at Shell for 6 years developing, deploying and customizing their SharePoint Environment. More recently, two years ago, I opened my own business, servicing a wide array of clients in their Office 365 and SharePoint deployments. In addition, I got introduced to Learning Tree and started teaching classes. With my new business and Learning Tree, I get to meet new people and get introduced to different work models and environments. The variety and constant change make everyday a new challenge and keeps things interesting. What do you love most about being an instructor? I love working with Learning Tree, the staff and other instructors. After I left Shell, a Learning Tree instructor reached out to me on LinkedIn to help with a large project he was working on. Working on the project, I was introduced to other Learning Tree instructors and got recruited to the Learning Tree family. And yes, Learning Tree is very much a warm, inviting family. In addition, Learning Tree’s working environment is very flexible. The work schedule, location, accommodations are all different per gig. Instructors are sent worldwide to teach. We are put in foreign situations. I believe that’s what makes learning Tree such a great environment, it’s part of the training and cultures to be more accepting and tolerant to other cultures and practices. What attributes do you take with you every day to work, and find the most important in succeeding? I would say confidence and being true to who you are. Everyone has their own unique experiences and perspectives. Bring that to the table makes you unique, special and an invaluable asset. You just need to be willing to put yourself out there. What is your biggest motivator? My kids. I want my girls to be confident and love themselves. They should know that they can accomplish anything they set their mind to and always be grateful for the small things in life. We all know actions speak louder than words. The only way to really teach my kids is by modelling that behavior. So, I push myself hard and hope the message seeps through. Who has been the biggest influence of your success? My mother. My mother is a hardworking, determined and persistent. She taught me what it means to go after what you want and never give up. In addition, behind every woman is a man cheering her on. My husband is my cheerleader, encouraging me to push past my fears and go ahead and succeed. Who are/have been your female icons and role models? Recently, my family celebrated Purim. The holiday celebrates a woman, Queen Esther, who is the heroine that saves the day. The tale opens with Queen Esther as a beautiful and obedient, but also a relatively passive figure. During the story, she evolves into someone who takes a decisive role in her own future and that of her people. Standing up for yourself and your beliefs is something that really resonated with me What does Women’s History Month mean to you? Is it important that we celebrate have one? We need to celebrate women! Women are the backbone of society and many times unseen and underappreciated for all their hard work. Who else is going to remind to wash your hands while the Coronavirus rages? What advice would you give to any young woman today? Be confident and communicate your needs clearly. Don’t avoid problems, face them head on even if it is uncomfortable. In the long run it will save you a lot of heart ache. Also, know your worth and don’t be shy to ask for it. And lastly, aim the stars, its closer than you think Thank you so much Malka for your insight, and all you do for Learning Tree and your attendees!